Jenkins Workflow is awesome. Just add a Jenkinsfile alongside your source and you can easily build a pipeline for your project. With Workflow, CloudBees and the Jenkins community are providing us with a first class tool to enable continuous delivery pipelines with Jenkins.

If you haven’t already heard, Apple open sourced Swift yesterday (Dec. 3, 2015). The Swift language is now available to download on GitHub . In today’s post we are going to take a quick look at running Apple Swift in a Jenkins Workflow.

But wait … don’t we need an OS X build node with XCode to do that? What a hassle, right? Well, actually you don’t need XCode or OS X anymore to build and run Swift code. You can read about the details on the Apple Swift GitHub page , but Swift is now officially supported on Ubuntu Linux. OK, so you can build and run Swift on Ubuntu, but that means that I need to configure a Ubuntu Linux build node with Swift. I don’t have time for that.

Now, here’s the awesome part: Jenkins Workflow has excellent support for Docker; hopefully you have already been using it (if not you can read more about Jenkins and Docker on CloudBees website ). And there is already a Docker image available for Ubuntu Linux with Swift installed . It only took me a few minutes to:

Here is the Jenkinsfile (Disclaimer: I’m not a Swift developer, yet):

//run this job on a docker enabled build node node('docker-cloud') { //this will pull the swift image, run it, and execute the following block of steps docker.image('swiftdocker/swift:latest').inside { //trivial, yes - but it works sh 'swift --version' } }

Here is part of the console output from running the Jenkins job:

Status: Downloaded newer image for swiftdocker/swift:latest [Workflow] Run build steps inside a Docker container : Start $ docker run -t -d -u 1000:1000 -w /home/jenkins/workspace/team-productivity/beedemo-sa/apple-swift-on-linux/master -v /home/jenkins/workspace/team-productivity/beedemo-sa/apple-swift-on-linux/master:/home/jenkins/workspace/team-productivity/beedemo-sa/apple-swift-on-linux/master:rw -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** swiftdocker/swift:latest cat [Workflow] withDockerContainer { [Workflow] sh [master] Running shell script + swift --version Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f82939c) Target: x86_64-unknown-linux-gnu [Workflow] } //withDockerContainer $ docker stop 0326b40b0bf1cb1ae5c23595e9892a86a422a1c4cb8e9489465c56b552cb6b50 $ docker rm -f 0326b40b0bf1cb1ae5c23595e9892a86a422a1c4cb8e9489465c56b552cb6b50 [Workflow] Run build steps inside a Docker container : End [Workflow] } //node [Workflow] Allocate node : End [Workflow] End of Workflow GitHub has been notified of this commit’s build result Finished: SUCCESS

I know this is a trivial Swift example, but the fact that you can so easily and quickly stand up a Swift build environment for Jenkins, well, that is pretty awesome!

Note: If you aren’t already using Docker with Jenkins and/or Workflow, here are some resources that will help you get started:

Kurt Madel

​Senior Solutions Architect

CloudBees