27
27
git. clean(' ' )
28
28
}
29
29
30
+ initMaven(mvn)
31
+
30
32
stage(' Build' ) {
31
33
mvn ' clean install -DskipTests'
32
34
archive ' **/target/*.jar'
@@ -39,14 +41,58 @@ node {
39
41
stage(' Integration Test' ) {
40
42
mvn ' verify -DskipUnitTests'
41
43
}
44
+
45
+ stage(' Deploy' ) {
46
+ if (preconditionsForDeploymentFulfilled()) {
47
+
48
+ mvn. setDeploymentRepository(' ossrh' , ' https://oss.sonatype.org/' , ' de.triology-mavenCentral-acccessToken' )
49
+
50
+ mvn. setSignatureCredentials(' de.triology-mavenCentral-secretKey-asc-file' ,
51
+ ' de.triology-mavenCentral-secretKey-Passphrase' )
52
+
53
+ mvn. deployToNexusRepositoryWithStaging()
54
+ }
55
+ }
42
56
}
43
57
44
58
// Archive Unit and integration test results, if any
45
59
junit allowEmptyResults : true ,
46
- testResults : ' **/target/surefire-reports/TEST-*.xml, **/target/failsafe-reports/*.xml'
60
+ testResults : ' **/target/surefire-reports/TEST-*.xml, **/target/failsafe-reports/*.xml'
47
61
48
62
// Find maven warnings and visualize in job
49
63
warnings consoleParsers : [[parserName : ' Maven' ]]
50
64
51
65
mailIfStatusChanged(git. commitAuthorEmail)
52
66
}
67
+
68
+ boolean preconditionsForDeploymentFulfilled () {
69
+ if (isBuildSuccessful() &&
70
+ ! isPullRequest() &&
71
+ shouldBranchBeDeployed()) {
72
+ return true
73
+ } else {
74
+ echo " Skipping deployment because of branch or build result: currentResult=${ currentBuild.currentResult} , " +
75
+ " result=${ currentBuild.result} , branch=${ env.BRANCH_NAME} ."
76
+ return false
77
+ }
78
+ }
79
+
80
+ private boolean shouldBranchBeDeployed () {
81
+ return env. BRANCH_NAME == ' master' || env. BRANCH_NAME == ' develop'
82
+ }
83
+
84
+ private boolean isBuildSuccessful () {
85
+ currentBuild. currentResult == ' SUCCESS' &&
86
+ // Build result == SUCCESS seems not to set be during pipeline execution.
87
+ (currentBuild. result == null || currentBuild. result == ' SUCCESS' )
88
+ }
89
+
90
+ void initMaven (Maven mvn ) {
91
+
92
+ if (" master" . equals(env. BRANCH_NAME )) {
93
+
94
+ echo " Building master branch"
95
+ mvn. additionalArgs = " -DperformRelease"
96
+ currentBuild. description = mvn. getVersion()
97
+ }
98
+ }
0 commit comments