From 3b471b46c5a8186f08a2d0c91fc529a96cd59c4d Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Mon, 25 Sep 2017 15:14:26 +0200 Subject: [PATCH] Adds Jenkinsfile --- Jenkinsfile | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..8faf17734 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,80 @@ +#!groovy +node { + + cesFqdn = "ecosystem.cloudogu.net"; + cesUrl = "https://${cesFqdn}"; + credentials = usernamePassword(credentialsId: 'system', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME'); + + stage('Checkout') { + checkout scm + } + + stage('Build') { + mvn "-DskipTests clean package" + + // archive artifact + archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true + } + + stage('Test') { + String jacoco = "org.jacoco:jacoco-maven-plugin:0.7.7.201606060606"; + mvn "${jacoco}:prepare-agent verify ${jacoco}:report" + + // Archive JUnit results, if any + junit allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml' + } + + stage('SonarQube Analysis') { + withCredentials([credentials]) { + //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/**" + } + } + + 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}" + } + + stage('Deploy Application') { + // ansible + } +} + +String cesFqdn; +String cesUrl; +def credentials; + +void mvn(String args) { + writeSettingsXml() + withEnv(["JAVA_HOME=${tool 'jdk8u112'}"]) { + sh "./mvnw -s settings.xml --batch-mode -V -U -e -Dsurefire.useFile=false ${args}" + } + sh 'rm -f settings.xml' +} + +void writeSettingsXml() { + withCredentials([credentials]) { + writeFile file: "settings.xml", text: """ + + ${env.HOME}/.m2/repository + + + ${cesFqdn} + ${USERNAME} + ${PASSWORD} + + + + + ${cesFqdn} + ${cesFqdn} Central Mirror + ${cesFqdn}/nexus/content/groups/public/ + central + + + """ + } +} \ No newline at end of file