Introduction
Jenkins has some great plugins for managing releases for Maven projects. You can tag projects in your source code repository, advance the versions, mark code as SNAPSHOTS, etc. And all of this can be done with one click of a button.
The simplicity of this release process made me start looking for other simple release plugins for projects that we not built using POM files. Unfortunately, I was unable to come up with something for Javascript based projects, so I ended up scripting my own.
gulp.js
Gulp is essentially a build file for javascript based applications, similar to Maven or Ant. Gulp is great when using Javascript as a language within a CI environment, as it will allow you to ‘build’ your code, execute unit tests, perform static or dynamic analysis on it, execute selenium front end tests, and even deploy the software. When combined with Angular or NodeJS, gulp becomes a VERY powerful tool.
My desire was to have the JS release process look similar to the maven release process done via the ‘Maven Release Plugin.’ To accomplish this, I had to do two things; add gulp tasks, and modify the Jenkins job. For the gulp task, I simply create two additional tasks, one for bumping the version, and one for tagging the code within our source code management. This will vary for every build job, but some more details on what I did within git can be found here and here. I also added add three build parameters: one boolean parameter for if it is a release or not, and two extended choice parameters for the release values.
- The Boolean parameter specified whether this build should be marked as a release or not
- The first Extended Choice Parameter was the current version. We decided to store this in the package.json file, and the default value of the parameter can be obtained using the below groovy script
import groovy.json.JsonSlurper;def slurper = new JsonSlurper()
String json = new File('/var/lib/jenkins/jobs/TaxonomyUI-Build/builds/lastSuccessfulBuild/archive/package.json').text
def result = slurper.parseText(json)return result.version
- The second Extended Choice Parameter was the next version. This was obtained by determining the current version, and incrementing, and the default value of the parameter can be obtained using the below groovy script
import groovy.json.JsonSlurper;def slurper = new JsonSlurper()
String json = new File('/var/lib/jenkins/jobs/TaxonomyUI-Build/builds/lastSuccessfulBuild/archive/package.json').text
def result = slurper.parseText(json)def parts = result.version.split("\\.")
++parts[-1]def version = parts.join(".")
return version
To ensure all of these values get properly picked up, we need to modify our build job slightly. Surrounding the deploy, we need to tag and bump the version in package.json
//if a release, make sure we tag it
if ${Release}; then
gulp tag --appVersion=${RELEASE_VERSION}
fi
gulp deploy
//if a release, make sure we bump it to the next version
if ${Release}; then
gulp bump --appVersion=${NEXT_VERSION}
fi
Finally, make sure the archive the package.json file so that the initial groovy scripts can find them.