Skip to content

Instantly share code, notes, and snippets.

@legolas
Created December 22, 2017 09:30
Show Gist options
  • Save legolas/92ab257615d3539d14fdb44ee93e148d to your computer and use it in GitHub Desktop.
Save legolas/92ab257615d3539d14fdb44ee93e148d to your computer and use it in GitHub Desktop.
Pipeline that builds a maven project and tags the git repo
pipeline {
agent {
docker {
label 'docker'
// Image containing java 8, maven 3.5.2 and git
image 'legolas/maven:3.5.2-jdk-8-alpine'
args '-v /root/.m2:/root/.m2'
}
}
environment {
VERSION_TAG='5.1.${BUILD_NUMBER}'
// TODO this needs to be retrieved from the ${REPOSITORY_URL} with the prefix 'https://' stripped off.
REPOSITORY_URL='repository.url/xxx/xxx/xxx.git'
}
stages {
stage('Validate pom') {
steps {
sh 'mvn -B validate'
}
}
stage('Set version') {
steps {
sh 'mvn -B versions:set -DnewVersion=${VERSION_TAG}'
}
}
stage('Tag the version') {
steps {
withCredentials([usernamePassword(credentialsId: 'my-credentials', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh "git tag ${VERSION_TAG}"
sh "git push https://${GIT_USERNAME}:${GIT_PASSWORD}@${REPOSITORY_URL} ${VERSION_TAG}"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment