Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An example for a Jenkins Declarative Multibranch Pipeline, triggering the jSparrow Maven plugin
pipeline {
agent any
tools {
jdk 'JDK8'
maven 'maven3'
}
options {
// we want to set the flag
skipDefaultCheckout true
}
environment {
JSPARROW_FLAG = true
}
stages {
stage('Checkout') {
steps {
checkout scm
script {
result = sh (script: "git log -1 --pretty=%B | grep '\\[jSparrow\\]'", returnStatus: true)
if (result == 0) {
JSPARROW_FLAG = false
}
echo "jSparrow flag: " + JSPARROW_FLAG
}
}
}
stage('Maven Version') {
steps {
sh "mvn --version"
}
}
stage('Maven Clean Verify') {
steps {
sh "mvn clean verify"
}
}
stage('jSparrow') {
when {
// only execute on feature branches..
branch pattern: "feature/.*", comparator: "REGEXP"
// ..and if the JSPARROW_FLAG is still true
expression {
JSPARROW_FLAG.toBoolean() == true
}
}
environment {
JSPARROW_LICENSE = credentials('JSPARROW_LICENSE')
}
steps {
// make the jsparrow.yml available with via configFileProvider
configFileProvider([configFile(fileId: 'JSPARROW_CONFIG', targetLocation: '/tmp/jsparrow.yml')]) {
sh "mvn jsparrow:refactor -Dlicense=$JSPARROW_LICENSE -DconfigFile=/tmp/jsparrow.yml"
}
// make the ssh key available via sshagent
sshagent(['SSH_KEY_ID']) {
sh "git config user.name 'jSparrow'"
sh "git config user.email 'info@jsparrow.eu'"
sh "git add --all"
sh "git commit -m '[jSparrow] automatic refactoring'"
sh "git push origin HEAD:$env.BRANCH_NAME"
}
}
}
}
post {
always {
script {
echo "Current build result: " + currentBuild.result
currentBuild.result = currentBuild.result ?: 'SUCCESS'
notifyBitbucket()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment