jenkinsci / hetzner-cloud-plugin

Hetzner cloud integration for Jenkins
https://plugins.jenkins.io/hetzner-cloud/
Apache License 2.0
24 stars 8 forks source link
agent cloud cloud-integration hetzner-cloud jenkins-agent jenkins-plugin

Hetzner Cloud Plugin for Jenkins

The Hetzner cloud plugin enables Jenkins CI to schedule builds on dynamically provisioned VMs in Hetzner Cloud. Servers in Hetzner cloud are provisioned as they are needed, based on labels assigned to them. Jobs must have same label specified in their configuration in order to be scheduled on provisioned servers.

Developed by

dNationCloud

Installation

Installation from update center

Installation from source

Configuration

Regardless of configuration method, you will need API token to access your Hetzner Cloud project. You can read more about creating API token in official documentation.

Manual configuration

1. Create credentials for API token

Go to Dashboard => Manage Jenkins => Manage credentials => Global => Add credentials, choose Secret text as a credentials kind:

add-token

2. Create cloud

Go to Dashboard => Manage Jenkins => Manage Nodes and Clouds => Configure Clouds => Add a new cloud and choose Hetzner from dropdown menu:

add-cloud-button

add-cloud

Name of cloud should match pattern [a-zA-Z0-9][a-zA-Z\-_0-9].

You can use Test Connection button to verify that token is valid and that plugin can use Hetzner API.

3. Define server templates

server-template

Following attributes are required for each server template:

These additional attributes can be specified, but are not required:

Scripted configuration using Groovy

import cloud.dnation.jenkins.plugins.hetzner.*
import cloud.dnation.jenkins.plugins.hetzner.launcher.*

def cloudName = "hcloud-01"

def templates = [
        new HetznerServerTemplate("ubuntu20-cx21", "java", "name=ubuntu20-docker", "fsn1", "cx21"),
        new HetznerServerTemplate("ubuntu20-cx31", "java", "name=ubuntu20-docker", "fsn1", "cx31")
]

templates.each { it -> it.setConnector(new SshConnectorAsRoot("my-private-ssh-key")) }

def cloud = new HetznerCloud(cloudName, "hcloud-token", "10", templates)

def jenkins = Jenkins.get()

jenkins.clouds.remove(jenkins.clouds.getByName(cloudName))
jenkins.clouds.add(cloud)
jenkins.save()

Configuration as a code

Here is sample of CasC file

---
jenkins:
  clouds:
    - hetzner:
        name: "hcloud-01"
        credentialsId: "hcloud-api-token"
        instanceCapStr: "10"
        serverTemplates:
          - name: ubuntu2-cx21
            serverType: cx21
            remoteFs: /var/lib/jenkins
            location: fsn1
            image: name=jenkins
            mode: NORMAL
            numExecutors: 1
            placementGroup: "key1=value1&key2=value2"
            connector:
              root:
                sshCredentialsId: 'ssh-private-key'
                connectionMethod: "default"
            shutdownPolicy: "hour-wrap"
          - name: ubuntu2-cx31
            serverType: cx31
            remoteFs: /var/lib/jenkins
            location: fsn1
            image: name=jenkins
            mode: EXCLUSIVE
            network: subsystem=cd
            labelStr: java
            numExecutors: 3
            placementGroup: "1000656"
            connectivity: "public-only"
            automountVolumes: true
            volumeIds:
              - 12345678
            connector:
              root:
                sshCredentialsId: 'ssh-private-key'
                connectionMethod: "public"
            shutdownPolicy:
              idle:
                idleMinutes: 10
credentials:
  system:
    domainCredentials:
      - credentials:
          - string:
              scope: SYSTEM
              id: "hcloud-api-token"
              description: "Hetzner cloud API token"
              secret: "abcdefg12345678909876543212345678909876543234567"
          - basicSSHUserPrivateKey:
              scope: SYSTEM
              id: "ssh-private-key"
              username: "jenkins"
              privateKeySource:
                directEntry:
                  privateKey: |
                    -----BEGIN OPENSSH PRIVATE KEY-----
                    b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn
                      ... truncated ...
                    baewZMKBL1QECTolAAAADHJrb3NlZ2lAbDQ4MAECAwQFBg==
                    -----END OPENSSH PRIVATE KEY-----

Server details

Plugin is able to report server details for any provisioned node

server details

Create server image using Packer

It's possible to create images in Hetzner Cloud using Packer.

Known limitations

Common problems

How to debug API calls

To enable debug logging for API calls, configure log recorder for logger cloud.dnation.hetznerclient.

add-log-recorder