re-add pgp credentials
[maven-build-process.git] / build / jenkins / Preview
blob1e21cd79c9fa7bd307d69dbd4f22563a6b069f07
1 node {
3     def repositoryLocation = ".repository"
4     def timestamp = new java.text.SimpleDateFormat('yyyy.MM.dd-HHmmss').format(new Date())
5     def mavenVersion = "maven-latest"
6     def mavenSettings = "repository.metio.wtf"
7     def releaseTarget = "metio"
8     def skipLocalStaging = "true"
10     stage('Cleanup') {
11         dir("${repositoryLocation}") {
12             deleteDir()
13         }
14     }
16     stage('Checkout') {
17         checkout scm
18     }
20     stage('Versioning') {
21         withMaven(
22                 maven: "${mavenVersion}",
23                 mavenSettingsConfig: "${mavenSettings}",
24                 mavenLocalRepo: "${repositoryLocation}") {
25             sh """
26                 mvn --batch-mode \
27                     --show-version \
28                     versions:set \
29                     -DgenerateBackupPoms=false \
30                     -DnewVersion=${timestamp}
31             """
32         }
33     }
35     stage('Analyze') {
36         withSonarQubeEnv('quality.metio.wtf') {
37             withMaven(
38                     maven: "${mavenVersion}",
39                     mavenSettingsConfig: "${mavenSettings}",
40                     mavenLocalRepo: "${repositoryLocation}") {
41                 sh """
42                     mvn --batch-mode \
43                         --show-version \
44                         sonar:sonar
45                 """
46             }
47         }
48     }
50     stage('Deploy') {
51         withCredentials([
52                 string(credentialsId: 'pgp.secretkey', variable: 'PGP_KEY'),
53                 string(credentialsId: 'pgp.passphrase', variable: 'PGP_PASSPHRASE')]) {
54             configFileProvider([configFile(fileId: "${mavenSettings}", variable: 'MAVEN_SETTINGS')]) {
55                 withMaven(
56                         maven: "${mavenVersion}",
57                         mavenLocalRepo: "${repositoryLocation}") {
58                     sh """
59                         mvn --batch-mode \
60                             --settings $MAVEN_SETTINGS \
61                             --show-version \
62                             pgp:sign deploy \
63                             -Drelease=${releaseTarget} \
64                             -DskipLocalStaging=${skipLocalStaging} \
65                             -Dpgp.secretKey=keyfile:${PGP_KEY} \
66                             -Dpgp.passphrase=literal:'${PGP_PASSPHRASE}'
67                     """
68                 }
69             }
70         }
71     }