Integrating with Jenkins
The Anka Jenkins plugin provides a quick way integrate Anka with Jenkins for iOS/macOS CI workflows using your own private cloud. Anka VMs can be allocated on-demand for execution of Jenkins build plans.
Preparing the VM Environment
Install Java for Jenkins
First, prepare your macOS VMs that you will use as VM templates in Jenkins with all necessary Jenkins JAR and Jenkins user access. This might include a dedicated Jenkins user within your VM template. One way to set up java dependencies for working with Jenkins is to execute the following commands in your VM template:
# Install Homebrew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" # Update Homebrew brew update # Add the caskroom tap brew tap Caskroom/cask # Install Java from the tap brew install Caskroom/cask/java
SSH or JNLP based Connection
Anka Build Jenkins plugin supports both JNLP and SSH based connections to Anka VMs. For JNLP, configure for JNLP in the Anka Build plugin in Jenkins.
SSH based Connection
User account configuration
Create a dedicated (Jenkins) user and enable remote login for this user in the VM template. Make sure to enable auto login for the administrative user of the VM as well.
Configure port forwarding
To prepare the VM for connections, shut down the VM using
anka stop VMNAME. Enable port forwarding for this VM using the following command:
anka modify VMNAME add port-forwarding --host-port 0 --guest-port 22 --protocol tcp RULENAME
Additional VM Template Setup
First, make sure to install any other build and test dependencies used for your Jenkins workflows in your VM template. Then, push this VM to the Anka registry (which is connected to your Anka Controller) using the
anka registry push command.
Configure the Anka Cloud Plugin
Install the Anka Build Cloud Plugin
Manage Jenkins > Manage Plugins and click on the
Advanced tab. Use the instructions under the Upload Plugin section to upload the
anka-ci.hpi plugin file to your Jenkins master server.
Then, go to
Manage Jenkins > Configure System and find the section called Cloud. Enter a name for your Anka Cloud in the Anka Build Cloud field, as well as an IP address and port number for the controller in the Build Controller URL field(http://xx.xxx.xxx.xxx:portno). Default port is 8090.
Next, click Show Templates and start configuring Jenkins slave templates for your jobs. Add multiple slave templates for different build and test job types as needed. While configuring the slave template, select your preconfigured VM template from Template drop down. Additionally select the version of the VM from the Template Version Tag dropdown.
You can save multiple slave VM template profiles based on your needs. Then, associate your Jenkins job with a specific label and run your jobs on these dynamically provisioned and isolated VMs. Your VM template should provision itself and become available when the job is executed.
Using the Anka Slave Template Prepare Plugin
Use this plugin to populate the VM templates with build cache. Before starting setup of this plugin, make sure that a VM template is available in the Anka Registry.
This plugin is not available through the Jenkins plugin center. Contact firstname.lastname@example.org to get the plugin package.
Step 1 - Upload “Anka Slave template Prepare” plugin hpi file to the Jenkins master server
Step 2 - Configure the “Anka Slave template Prepare” plugin
Step 2.1 - Pick a mac machine to use as the host for Slave template prepare plugin and install Anka Build.pkg on it. Note - This machine should not be part of the Anka Build cloud cluster.
Step 2.2 - Connect the host from step 2.1 to Anka registry using the following command
anka registry add.
Step 2.3 - Create a ssh user on the host from step 2.1 for jenkins connection.
Step 2.4 - Configure following settings in the ‘Anka Slave Template Prepare Plugin’ settings.
Cloud Name - Enter a name for Anka slave template prepare cloud. Anka Host name or IP - Enter the IP of the host from step 2.1. Credentials - Enter ssh user credentials from step 2.3.
Slave Template settings
Template - Select the base macOS Vm template from the list. Template version tag - Select a specific tag or leave to latest. Latest is the last pushed version. Remote FS root - Jenkins user root directory in the base macOS VM template. Labels - Specify the label for this slave that will be used in the job. Clone user - jenkins user credentials for the slave (VM).
Step 2.5 - In the Jenkins job configuration, specify the label from step 2.4 slave template setting. Also, include post build step Action in the job. In the post build action, enter the following information.
Tag name - It’s recommended to leave it empty and the plugin will self-generate a tag with the current date or specify a specific tag name for the VM that is available after the build job and will be pushed as VM template to the registry.
Delete latest tag - In order to optimize disk space in the registry. You can select this option. When a new version of Vm template is pushed to the registry, the previous tag will be deleted.
Tag description - text description for the tag/version.
Step 2.6 - In the Anka Build Cloud plugin, select the VM template from step 2.4 for your slave template and select ‘latest’ in the tag field. This will ensure that the main CI jobs use the VM that is prepared with caches by the Slave Template Prepare plugin.