Latest posts

Uploading Git Changelog to Fabric Beta for Android Gradle Builds in Jenkins

We now use Fabric Beta to distribute our automated builds of our iOS and Android apps that are built by Jenkins. However it makes it much easier to see what is in a build if you can have the changelog uploaded with the binary.

For some reason I don’t quite understand, whilst GIT_BRANCH and various other Git environment variables are exposed by the Git SCM module in Jenkins, the changelog is not.

Based on some code I found in a Jenkins ticket I put a method in our Jenkinsfile to get the changelogs so we can put them in an environment variable:

def getChangelog() {
    def changeLogSets = currentBuild.rawBuild.changeSets
    def changelog = ""
    for (int i = 0; i < changeLogSets.size(); i++) {
        def entries = changeLogSets[i].items
        for (int j = 0; j < entries.length; j++) {
            def entry = entries[j]
            changelog += entry.msg + ‘\n
        }
    }
    return changelog
}

env.GIT_CHANGELOG = getChangelog()

We then need to pass this to the Gradle task we run to include the notes when we upload the .apk to Crashlytics / Fabric Beta:

def releaseNotes = "${env.GIT_BRANCH}\n\n${env.GIT_CHANGELOG}"
env.ORG_GRADLE_PROJECT_BETA_RELEASE_NOTES=releaseNotes
sh "./gradlew crashlyticsUploadDistributionDevRelease"

I discovered that if you set an environment variable with the prefix ORG_GRADLE_PROJECT_ then Gradle will pick that up and set it as a project property. This neatly gets around trying to pass it using the -P flag to the gradlew command and having to worry about escaping quotes in shell parameters. Also saves trouble if little Bobby Tables writes a commit log. ;)

We add in the Git branch to the top of the release notes so that when you look at the list of builds in the Fabric Beta app you can easily see which branch they came from.

Then in our build.gradle file we can find this project property and put that where the Crashlytics task will be expecting it:

    buildTypes {
        debug {
        }
        release {
            if (project.hasProperty("BETA_RELEASE_NOTES")) {
                ext.betaDistributionReleaseNotes = project.property('BETA_RELEASE_NOTES')
                println(String.format("Beta Distribution Release Notes: %s", ext.betaDistributionReleaseNotes))
            }
            ext.betaDistributionNotifications = false
            ext.betaDistributionGroupAliases = "android-testers"
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

The end result is that in the Fabric Beta mobile app on Android you can easily see the branch name and commit notes for each build. As we automatically build each feature branch the is pushed to Github this makes it much easier to see which build is which when you want to go and install a particular build to check out a particular feature branch:

A screenshot of the branch name and commit log showing in the Android Fabric Beta app.

Global Build Numbers in Jenkins Multibranch Pipeline Builds

We wanted to have build numbers that were unique and incremental across all of our build jobs. Here is how I did it with a small python microservice.

Jenkins 2.0 and Multi-branch pipeline builds for iOS apps with Fastlane

Jenkins 2.0 beta is out and has included a multi-branch pipeline plugin that allows automatic build of feature branches from Github. Here is how I set it up to build feature branch builds of our iOS apps

Getting Proper UTF-8 Output From Fastlane on Jenkins 2.0 Pipeline builds

Jenkins 2.0 pipeline jobs get their locale from the master not slave, so you need to set the local on master to get UTF-8 output working correctly

Safer deleting of a directory

A safer alternative to rm -rf for use in scripts

Jenkins, Github, and IPv6

Github and some other sites don't yet support IPv6. But I want our build servers to be IPv6 only. Here is how I achieved it using OpenBSD's NAT64 and unbound's DNS64 functions

Smart Nation Singapore - Bristol Festival of Ideas - Festival of the Future City

Singapore aims to be the world’s first Smart Nation, with fuller use of technology to live, work and play resulting in improved quality of life for individuals; business opportunities for enterprises; and a government that uses technology to better serve and anticipate citizens’ needs.

NSScotland 2015 Conference

A write up of some of the talks I found interesting at the NSScotland conference in Edinburgh. Dealing with maps; Building a mental health app; Working with distributed teams; and a 30-year old calculator codebase

Force git to use ssh instead of HTTPS

Sometimes you have tools that reference a github url with https and you want them to use ssh instead so your ssh key works

Plone Conference 2015 - Bucharest

The Plone Conference 2015 happened in Bucharest, Romania. Once again, an awesome event! Great keynotes on the state of Plone and accessibility.