11#! groovy
2- @Library (' github.com/cloudogu/ces-build-lib@9789d0b ' )
2+ @Library (' github.com/cloudogu/ces-build-lib@7e3090c ' )
33import com.cloudogu.ces.cesbuildlib.*
44
55properties([
@@ -22,10 +22,7 @@ node {
2222
2323 stage(' Checkout' ) {
2424 checkout scm
25- /* Don't remove folders starting in "." like
26- * .m2 (maven), .npm, .cache, .local (bower)
27- */
28- git. clean(' ".*/"' )
25+ git. clean(' ' )
2926 }
3027
3128 initMaven(mvn)
@@ -54,18 +51,50 @@ node {
5451 currentBuild. result = ' UNSTABLE'
5552 }
5653 }
54+
55+ stage(' Deploy' ) {
56+ if (preconditionsForDeploymentFulfilled()) {
57+
58+ mvn. setDeploymentRepository(' ossrh' , ' https://oss.sonatype.org/' , ' de.triology-mavenCentral-acccessToken' )
59+
60+ mvn. setSignatureCredentials(' de.triology-mavenCentral-secretKey-asc-file' ,
61+ ' de.triology-mavenCentral-secretKey-Passphrase' )
62+
63+ mvn. deployToNexusRepositoryWithStaging()
64+ }
65+ }
5766 }
5867
59- // Archive Unit and integration test results, if any
68+ // Archive Unit and integration test results, if any
6069 junit allowEmptyResults : true ,
6170 testResults : ' **/target/surefire-reports/TEST-*.xml, **/target/failsafe-reports/*.xml'
6271
63- // Find maven warnings and visualize in job
72+ // Find maven warnings and visualize in job
6473 warnings consoleParsers : [[parserName : ' Maven' ]]
6574
6675 mailIfStatusChanged(getCommitAuthorOrDefaultEmailRecipients(env. EMAIL_RECIPIENTS_COMMAND_BUS ))
6776}
6877
78+ boolean preconditionsForDeploymentFulfilled () {
79+ if (isBuildSuccessful() &&
80+ ! isPullRequest() &&
81+ shouldBranchBeDeployed()) {
82+ return true
83+ } else {
84+ echo " Skipping deployment because of branch or build result: currentResult=${ currentBuild.currentResult} , " +
85+ " result=${ currentBuild.result} , branch=${ env.BRANCH_NAME} ."
86+ return false
87+ }
88+ }
89+
90+ private boolean shouldBranchBeDeployed () {
91+ return env. BRANCH_NAME == ' master' || env. BRANCH_NAME == ' develop'
92+ }
93+
94+ private boolean isBuildSuccessful () {
95+ currentBuild. currentResult == ' SUCCESS' && currentBuild. result == ' SUCCESS'
96+ }
97+
6998void initMaven (Maven mvn ) {
7099
71100 if (" master" . equals(env. BRANCH_NAME )) {
0 commit comments