Within this page, we'll describe how we set up Jenkins on our server to meet our requirements. Out of all the tools that are out there we chose Jenkins because it's one of the more popular CI systems. Since it actually is so popular, you'll also find a lot of stuff on the internet on how to do certain things properly because there will have been people who already ran into similar problems. We were considering to use XCode Server from Apple as a CI but due to the restrictions to Apple we were rejecting this idea pretty fast.
Download the latest Jenkins .war file from the offical Jenkins homepage. On our server, we moved the .war file into the applications folder and created a separate Jenkins folder where we kept all of the Jenkins files together. You can handle this any way you want though by moving the files to a place suitable for you.
Open the terminal and start Jenkins with
1 | java -jar /path/to/Jenkins/jenkins.war & |
The path to the .war file depends on where you saved it on your system. After firing up the command you might face some error if you don't have at least Java Version 7 installed.
If you need to upgrade to the latest Java Version you need to do following steps:
1 | sudo rm /usr/bin/java |
This command will remove the old symbol link which points to
/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java (That's Apple's 1.6 Java Version). Now you need to set a new symbolic link to the new Java version.
1 | sudo ln -s /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin |
After that, try again if you can successfully start Jenkins using the command
1 | java -jar /Applications/Jenkins/jenkins.war & |
Once done and you don't see any further error messages in the terminal you can access Jenkins via the Webfrontend http://localhost:8080/ and it should look something like below.
Jenkins doesn't force you to use any authentication method at all. You should take care of this yourself by activating the security settings though because Jenkins is usually reachable over the network and could be quite easily accessible without any security features.
In our case the following changes have been made under Manage Jenkins > Configure Global Security > Enable Security:
Here we activated Jenkins own user database under the sectionSecurity Realm, don't forget users to signup. Once everyone is registered you should deactivate this feature again. Otherwise it's still insecure because everyone can register by himself and has admin rights. We left the Authorization field as it was: Logged-in users can do anything.
In case you use Gerrit you should also add a Jenkins user for Gerrit.
Once you're finished tweaking the settings, don't forget to save all of your changes.
The benefits of an open-source platform with a large userbase helps you again when it comes to adding additional functionality to Jenkins: There's a multitude of plugins! Below, you'll find the plugins that we thought were necessary for our system:
You can install all of the plugins above and much more by accessing "Manage Jenkins" > "Manage Plugins". Select the "Available" tab from the overview and from there, choose any plugin that you want to install by hitting "Download now and install after restart". In the next section we'll cover the configuration for the plugins that we used.
In order to use our freshly installed plugins, we must configure them correctly.
In order for the plugin to use the command line tools that Xcode provides, you must have Xcode installed on your machine. If not already installed, download it from the AppStore (it's free) and open it at least once. This should make it install all of the necessary tools it needs. Later on, if you want to run automated Unit Tests, you'll also need to install an iOS simulator because otherwise the jobs that include testing won't work properly. Hence, go to the statusbar while running Xcode and open "Xcode" > "Preferences". In the "Downloads" tab, you'll see a list of all simulator versions available. Select the one(s) you need and install them immediately.
Configure the Gerrit Plugin in "Manage Jenkins" > "Gerrit Trigger"
Select "Add new server" on the left and enter a name for your Gerrit server and choose "Gerrit Server with Default Configurations".
In the field "Frontend URL", enter the server address of your Gerrit including the port number - if you're working on the same machine, it could just be the localhost (e.g. http://127.0.0.1:8081). In order to connect via SSH, we need port 29418. You then need to enter the username that you added earlier in Preparing Gerrit for Jenkins Integration - in our case "jenkins". Additionally, add the SSH Keyfile (private key) and password which you generated for Jenkins in Gerrit. Further changes can be made regarding the values which will be given from Jenkins to Gerrit once triggered.
Now you can start setting up your Jenkins Jobs. A job can have different tasks - normally a project consists of different jobs which have different purposes like executing unit tests, building artefacts and so on.
In our case we created two separate Jobs which differentiate in a few settings.
For creating a new job, select "New Item" on the left side. Assign a project name, in our case "Build and test PatchSet on dev" as "Freestyle project" and select OK.
In the first section are settings about Slack configured. We set a checkmark for "Notify Failure" and "Notify Success" so that we get notified in those two cases.
In order for the notifications to actually be sent, you'll have to add a "Post-build Action" > "Slack notifications". Once done, it should automatically send notifications.
As build trigger you select "Gerrit event".
Now we setup our Xcode Plugin, therefore you need to add a new build step and select "Xcode".