diff --git a/Jenkinsfile b/Jenkinsfile index f102d0f1f..05665b34d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,14 +1,19 @@ #!groovy -node { +@Library('github.com/cloudogu/ces-build-lib@caa9632') +import com.cloudogu.ces.cesbuildlib.* - properties([ +properties([ // Don't run concurrent builds, because the ITs use the same port causing random failures on concurrent builds. disableConcurrentBuilds() - ]) +]) + +node { cesFqdn = findHostName() cesUrl = "https://${cesFqdn}" - credentials = usernamePassword(credentialsId: 'scmCredentials', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME') + String credentialsId = 'scmCredentials' + + Maven mvn = new MavenWrapper(this) catchError { @@ -39,7 +44,8 @@ node { ) stage('SonarQube Analysis') { - withCredentials([credentials]) { + withCredentials([usernamePassword(credentialsId: credentialsId, + passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) { //noinspection GroovyAssignabilityCheck mvn "org.codehaus.mojo:sonar-maven-plugin:3.2:sonar -Dsonar.host.url=${cesUrl}/sonar " + "-Dsonar.login=${USERNAME} -Dsonar.password=${PASSWORD} -Dsonar.exclusions=target/**" @@ -47,9 +53,9 @@ node { } stage('Deploy Artifacts') { - String releaseProp = "-DaltReleaseDeploymentRepository=${cesFqdn}::default::${cesUrl}/nexus/content/repositories/releases/"; - String snapshotProp = "-DaltSnapshotDeploymentRepository=${cesFqdn}::default::${cesUrl}/nexus/content/repositories/snapshots/"; - mvn "-DskipTests deploy ${releaseProp} ${snapshotProp}" + mvn.setDeploymentRepository(cesFqdn, "${cesUrl}/nexus", credentialsId) + + mvn.deployToNexusRepository('-Dmaven.javadoc.failOnError=false') } } @@ -60,44 +66,3 @@ node { // Init global vars in order to avoid NPE String cesFqdn = '' String cesUrl = '' -def credentials= {} - -void mvn(String args) { - writeSettingsXml() - sh "./mvnw -s settings.xml --batch-mode -V -U -e -Dsurefire.useFile=false ${args}" - sh 'rm -f settings.xml' -} - -String findHostName() { - String regexMatchesHostName = 'https?://([^:/]*)' - - // Storing matcher in a variable might lead to java.io.NotSerializableException: java.util.regex.Matcher - if (!(env.JENKINS_URL =~ regexMatchesHostName)) { - script.error 'Unable to determine hostname from env.JENKINS_URL. Expecting http(s)://server:port/jenkins' - } - return (env.JENKINS_URL =~ regexMatchesHostName)[0][1] -} - -void writeSettingsXml() { - withCredentials([credentials]) { - writeFile file: "settings.xml", text: """ - - ${env.HOME}/.m2/repository - - - ${cesFqdn} - ${USERNAME} - ${PASSWORD} - - - - - ${cesFqdn} - ${cesFqdn} Central Mirror - ${cesUrl}/nexus/content/groups/public - central - - - """ - } -}