Create a Declarative Pipeline Jenkinsfile for Maven Releasing

Build on Commit, Release on Demand

The first — rather easy — problem was to create a Job that would build each commit on master and releases whenever needed.

parameters {
booleanParam(
name: "RELEASE",
description: "Build a release from current commit.",
defaultValue: false)
}
when { expression { params.RELEASE } }
when {
allof {
branch "development"
expression { params.RELEASE }
}
}
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:prepare (default-cli) on project date-time-test-support: An error is occurred in the checkin process: Exception while executing SCM command. Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref -> [Help 1]

Checkout to local Branch

The reason is, that Jenkins’ default clone behavior, which clones a single commit, instead of a branch. This is a problem once Maven tries to commit and push the changed pom.xml and the release tag.

scm { git("...", "*/master") }
scm {
git {
remote {
url("...")
branch("*/master")
}
extensions {
localBranch("master")
}
}
}

--

--

I've been a software engineer since 2009, worked in various agile projects & got a taste for quality assurance. Today I'm a quality engineer at REWE digital.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Michael Kutz

Michael Kutz

I've been a software engineer since 2009, worked in various agile projects & got a taste for quality assurance. Today I'm a quality engineer at REWE digital.