simplify pipelines
[maven-build-process.git] / build / jenkins / Release
blobaad6a7aee577dc8ae0a5ce963dddb7335de3addc
1 node {
3     def projectName = "sebhoss/maven-build-process"
4     def repositoryLocation = ".repository"
5     def timestamp = new java.text.SimpleDateFormat('yyyy.MM.dd-HHmmss').format(new Date())
6     def mavenVersion = "maven-latest"
7     def mavenSettings = "repository.metio.wtf"
8     def releaseTarget = "sonatype"
9     def skipLocalStaging = "false"
10     def githubCredentials = "build-metio-wtf-github"
12     stage('Cleanup') {
13         dir("${repositoryLocation}") {
14             deleteDir()
15         }
16     }
18     stage('Checkout') {
19         checkout scm
20     }
22     stage('Versioning') {
23         withMaven(
24                 maven: "${mavenVersion}",
25                 mavenSettingsConfig: "${mavenSettings}",
26                 mavenLocalRepo: "${repositoryLocation}") {
27             sh """
28                 mvn --batch-mode \
29                     --show-version \
30                     versions:set \
31                     -DgenerateBackupPoms=false \
32                     -DnewVersion=${timestamp}
33             """
34         }
35     }
37     stage('Analyze') {
38         withSonarQubeEnv('quality.metio.wtf') {
39             withMaven(
40                     maven: "${mavenVersion}",
41                     mavenSettingsConfig: "${mavenSettings}",
42                     mavenLocalRepo: "${repositoryLocation}") {
43                 sh """
44                     mvn --batch-mode \
45                         --show-version \
46                         sonar:sonar
47                 """
48             }
49         }
50     }
52     stage('Deploy') {
53         configFileProvider([configFile(fileId: "${mavenSettings}", variable: 'MAVEN_SETTINGS')]) {
54             withMaven(
55                     maven: "${mavenVersion}",
56                     mavenLocalRepo: "${repositoryLocation}") {
57                 sh """
58                     mvn --batch-mode \
59                         --show-version \
60                         --settings $MAVEN_SETTINGS \
61                         pgp:sign deploy \
62                         -Drelease=${releaseTarget} \
63                         -DskipLocalStaging=${skipLocalStaging}
64                 """
65             }
66         }
67     }
69     stage('Tag') {
70         withMaven(
71                 maven: "${mavenVersion}",
72                 mavenSettingsConfig: "${mavenSettings}",
73                 mavenLocalRepo: "${repositoryLocation}") {
74             sh """
75                 mvn --batch-mode \
76                     --show-version \
77                     scm:tag \
78                     -DpushChanges=false
79             """
80         }
81     }
83     stage('Git Push') {
84         withCredentials([
85                 string(credentialsId: 'git.user.name', variable: 'GIT_USER'),
86                 string(credentialsId: 'git.user.email', variable: 'GIT_EMAIL'),
87                 [$class: 'UsernamePasswordMultiBinding', credentialsId: "${githubCredentials}",
88                             usernameVariable: 'USERNAME', passwordVariable: 'TOKEN']]) {
89             sh "git config user.name '${GIT_USER}'"
90             sh "git config user.email '${GIT_EMAIL}'"
91             sh "git push https://${TOKEN}:x-oauth-basic@github.com/${projectName}.git --tags"
92         }
93     }