Skip to content

Instantly share code, notes, and snippets.

@luigiwerzowa
Created October 8, 2020 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luigiwerzowa/aafba402bd36faa573f48a26fc056289 to your computer and use it in GitHub Desktop.
Save luigiwerzowa/aafba402bd36faa573f48a26fc056289 to your computer and use it in GitHub Desktop.
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