Last active
July 10, 2018 12:47
-
-
Save s-petit/31134f06ff93f3f2bb36a6b94a5dc87f to your computer and use it in GitHub Desktop.
Perform a maven release via a Jenkins pipeline with declarative syntax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env groovy | |
| pipeline { | |
| stages { | |
| stage('Prepare') { | |
| steps { | |
| withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'YOUR_CREDENTIALS_ID', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) { | |
| sh 'mvn -B release:prepare -Dusername=$GIT_USERNAME -Dpassword=$GIT_PASSWORD' | |
| } | |
| } | |
| } | |
| stage('Perform') { | |
| steps { | |
| withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'YOUR_CREDENTIALS_ID', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) { | |
| sh 'mvn -B release:perform -Dusername=$GIT_USERNAME -Dpassword=$GIT_PASSWORD -Darguments="-DskipTests"' | |
| } | |
| } | |
| } | |
| } | |
| post { | |
| failure { | |
| echo 'An unexpected error occurred during release. Rollbacking...' | |
| withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'YOUR_CREDENTIALS_ID', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) { | |
| sh 'mvn -B release:rollback -Dusername=$GIT_USERNAME -Dpassword=$GIT_PASSWORD' | |
| } | |
| } | |
| cleanup { | |
| sh 'mvn release:clean' | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment