The Jenkins Anka Plugin provides a quick way to integrate Anka Build Cloud with Jenkins. The plugin helps Jenkins jobs dynamically provision Anka VM instances (based on the label used) for building, testing, and more.
In order to follow these instructions, you will need to install the Anka CLI and an understanding of how to start the VM and launch the viewer.
The Jenkins Anka Plugin requires a VM with Java, SSH Remote Login, and port forwarding:
System Properties
) and look for java.version
.java.version
is set to 1.8.0_242
, you can download and install the AdoptOpenJDK jdk8u242-b08.pkg.You can run any version of JAVA you want as long as the version inside of the VM matches your Jenkins server
System Preferences > Sharing
).sudo anka suspend <VM Template name>
sudo anka registry push <VM Template name> <Tag name>
These steps are based on Jenkins 2.289.1 and the Anka Jenkins Plugin v2.6.0. Your version/UI may differ slightly.
Navigate to Manage Jenkins > Manage Plugins
and click on the Available tab. Search in Filter for “Anka”, then install it. You won't see any results if it's already installed.
Now you can configure the Anka Cloud. Navigate to Manage Jenkins > Manage Nodes and Clouds
and find the section called Configure Clouds
. Inside of Configure Clouds
, click on Add a new Cloud at the bottom of the page and then click on Anka Build Cloud Plugin.
You now have an Anka Build Cloud Plugin panel exposed to do your configuration. You can set Cloud Name to be anything you want. However, you'll need to set Full Anka Build Cloud Controller URL to the proper URL of your controller, and make sure you include the port: http://<ip/domain>:80
. Once you're done, click Save.
At this point you can either setup Static Labels or use Dynamic Labelling in your Jenkinsfile.
Return to Manage Nodes and Clouds > Configure Clouds
. You should now see a Jenkins Node/Agent Templates and Labels section. Make sure Show Agent/Node Templates is checked and click on Add. This creates a new Template you can edit.
Under the Template, you want to select the proper Anka VM Template and Anka VM Template's Tag or leave the tag selection to the default value to select the latest Tag in the Registry.
(Optional) Set Node/Agent Description
Select the SSH or JNLP method for connection between Jenkins and your Anka VMs.
anka
and pass: admin
./tmp/log.txt
for errors.(Optional) Set Maximum Allowed Nodes/Agents if you need to limit the amount of agents that any jobs are allowed to start.
(Optional) Set Allowed Executors if you want to allow a single agent to be used for multiple jobs.
(Optional) Set Anka VM Workspace Path if you'd like for the job to work within a specific path inside of the VM.
(Optional) Set any Environment Variables necessary for your jobs
There are several other configs under Advanced that may interest you. These include the Node Group, Priority, and timeouts for Jenkins to communication with the starting Anka VM/agent.
Dynamic Labelling requires two plugins: GitHub Authentication plugin and Pipeline.
This section describes the steps to create dynamic labels inside of your Jenkinsfile using the createDynamicAnkaNode
function.
createDynamicAnkaNode
function starts a VM and returns a unique label for it.createDynamicAnkaNode
has all the configuration options that the UI configured Static Slave Template has.Jenkins has a Pipeline Snippet Generator, which helps you craft your
createDynamicAnkaNode
definition. You can find it in your Jenkins instance at/pipeline-syntax
.
CreateDynamicAnkaNode
ParametersYou can obtain the “masterVmId” (VM UUID) using:
sudo anka show <Template name> uuid
Name | Type | Default Value | Description | Required |
---|---|---|---|---|
masterVmId | String | - | UUID of the VM Template | Yes |
tag | String | - | VM Template Tag name | - |
remoteFS | String | Users/anka | Remote node workspace | - |
launchMethod | String | jnlp | Node launch method: ‘ssh’ or ‘jnlp’ | - |
credentialsId | String | - | Jenkins credential ID for ssh launch method | - |
extraArgs | String | - | String to be appended to JNLP command | - |
javaArgs | String | - | String to append to JNLP java args | - |
jnlpJenkinsOverrideUrl | String | - | Override the Jenkins server url set in the Jenkins configuration | - |
jnlpTunnel | String | - | JNLP tunnel to use for node launcher | - |
keepAliveOnError | boolean | false | Keep the VM instance alive after a failed build | - |
timeout | int | 1200 | Timeout for starting the instance (in seconds) | - |
environments | List of tuples | - | List of environment variables to add for the build: [[name: 'FOO', value: 'BAR'], [name: 'OR', value: 'IS']] | - |
nameTemplate | string | - | Label to use in VM instance names (There are several variables available for interpolation: $Template_name, $Template_id, or $ts) | - |
priority | int | 1000 | Override the default priority (lower is more urgent). Available only in Enterprise and Enterprise Plus Tiers | - |
saveImage | boolean | false | Save the VM as a Tag before terminating it | - |
suspend | boolean | false | When saving the Tag, suspend the VM before the push | - |
TemplateId | string | - | When saving the Tag, push onto a specific Template UUID | - |
pushTag | string | - | When saving the Tag, set the Tag name (A timestamp will be appended) | - |
deleteLatest | boolean | false | When saving the Tag, delete the latest Tag for the Template out of the registry before pushing (Dangerous: only use if the Template isn't holding other project tags) | - |
TemplateDescription | string | - | When saving the Tag, set a description for the new Tag | - |
group | string | - | Group ID to start the instance in (Available only in Enterprise and Enterprise Plus Tiers) | - |
numberOfExecutors | int | 1 | Number of Jenkins executors to run on the Node (we recommend 1) | - |
description | string | - | On creation of the instance, set the description | - |
labelString | string | - | Override the returned label (not recommended) | - |
dontAppendTimestamp | boolean | false | Do not append timestamp to the tag being pushed | - |
def NODE_LABEL = createDynamicAnkaNode(
masterVmId: 'e1173284-39df-458c-b161-a54123409280'
)
pipeline {
agent {
label "${NODE_LABEL}"
}
stages {
stage("hello") {
steps {
sh "echo hello"
}
}
}
}
Anka VM Template/Tag Creation is useful when you need to automate the preparation of a VM with dependencies. You can setup a separate Jenkins job/pipeline to execute preparation scripts inside of a VM and then push to the registry with a specific tag. Other jobs can then target the latest tag and immediately start using the new VM template/tag.
The plugin will push to the Registry for any buildStatus except for FAILURE, ABORTED, or UNSTABLE. You can wrap your step-level commands in
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE')
or use the Build Execute shell advanced Exit code to set build unstable setting to prevent the VM from pushing.
You can find the Anka VM Template/Tag Creation in the Jenkins Node/Agent Templates and Labels section under Manage Jenkins > Manage Nodes and Clouds > Configure Clouds
.
Fail build : Will set the build as failed if the image save request
failed (or timed out). If this is not selected, the Post Build Step does nothing.
Timeout : Sets the minutes to wait for the Tag push to Registry to complete (this needs to be determined manually or with trial and error).
Pipelines can have multiple agents running in one build (also in parallel). Therefore, the plugin relies on the buildResult to tell if it needs to execute the “save image request”. You have two options to prevent pushing the new Tag prematurely:
stage("run-on-NESTED_LABEL-vm") {
agent { label "${NESTED_LABEL}" }
steps {
// If buildResults == 'FAILURE', Anka will not push the NESTED_LABEL VM. Example:
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
sh 'uname -r;'
}
}
}
Please review our Nested Cache Builder Example.
If buildResult receives any of the failed statuses (FAILURE, ABORTED, or UNSTABLE), the ankaGetSaveImageResult outputs
Checking save image status… Done!
in the Jenkins job logs/console since there is no push operation to wait on.
Create an ankaGetSaveImageResult
Pipeline step:
stage("check-generated-tag-from-nested-vm") {
steps {
script {
def getPushResult = ankaGetSaveImageResult( shouldFail: true, timeoutMinutes: 120 )
echo "ankaGetSaveImageResult Returned: $getPushResult"
}
}
}
If you're creating multiple cache Tags in a single pipeline, The ankaGetSaveImageResult
function returns true if all previous image save calls for this particular build have executed.
Name | Type | Default Value | Decription | Required |
---|---|---|---|---|
shouldFail | boolean | true | Fails the job if one of the image save requests has failed or timed out | |
timeoutMinutes | int | 120 | Stops waiting for the result of the Tag -> Registry push after x minutes. |
Remember,
ankaGetSaveImageResult
returns true immediately if nothing pushes to the Registry in a failed build.
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.