80 lines
3.6 KiB
Groovy
80 lines
3.6 KiB
Groovy
#!groovy
|
|
|
|
// this groovy script is executed by jenkins
|
|
node {
|
|
|
|
// set environment variables
|
|
env.ANDROID_SDK_ROOT = '/var/lib/android-sdk'
|
|
env.JAVA_HOME = '/opt/openjdk-bin-21'
|
|
env.PATH = "${env.JAVA_HOME}/bin:${env.PATH}"
|
|
|
|
// checkout code from scm
|
|
stage('Checkout') {
|
|
checkout scm
|
|
}
|
|
|
|
def version = ''
|
|
def release = false;
|
|
|
|
// configure the deployer based on the version
|
|
stage('Configure') {
|
|
version = sh(returnStdout: true, script: "./gradlew properties -q | grep \"version:\" | awk '{print \$2}'", label: "Detecting project version.").trim()
|
|
println "Version is: '${version}'"
|
|
release = (! version.endsWith("-SNAPSHOT"))
|
|
}
|
|
|
|
// build the source code with gradle
|
|
stage('Build') {
|
|
withCredentials([string(credentialsId: 'mowesta-keystore-password', variable: 'PASSWD')]) {
|
|
sh(script: './gradlew -Djenkins.build.number=' + env.BUILD_NUMBER + ' -Dandroid.keystore.password=$PASSWD clean build -x test', label: "Building project.")
|
|
}
|
|
}
|
|
|
|
// deploy the maven publications to nexus
|
|
stage ('Publish') {
|
|
if (env.BRANCH_NAME == "master") {
|
|
withCredentials([string(credentialsId: 'jenkins-nexus-password', variable: 'NEXUS')]) {
|
|
withCredentials([string(credentialsId: 'mowesta-keystore-password', variable: 'PASSWD')]) {
|
|
sh(script: './gradlew -Djenkins.build.number=' + env.BUILD_NUMBER + ' -Dandroid.keystore.password=$PASSWD -Djenkins.nexus.password=$NEXUS publishAllPublicationsToMavenRepository', label: "Publishing project.")
|
|
}
|
|
}
|
|
} else {
|
|
echo "Skipping publication for non-release version or non-master branch."
|
|
}
|
|
}
|
|
|
|
// deploy the build output on the server
|
|
stage ('Deploy') {
|
|
// release = true; // uncomment to temporary enable snapshot deployments
|
|
|
|
// copy android bundles to apps pro
|
|
if (env.BRANCH_NAME == "master") {
|
|
echo "Copying android bundles to production server ..."
|
|
withCredentials([sshUserPrivateKey(credentialsId: "mowesta-server-key", keyFileVariable: "KEYFILE")]) {
|
|
sh 'scp -i $KEYFILE android-app/build/outputs/apk/prod/release/*.apk wildfly@apps-pro.nes.uni-due.de:/opt/android/mowesta/'
|
|
sh 'scp -i $KEYFILE android-app/build/outputs/bundle/prodRelease/*.aab wildfly@apps-pro.nes.uni-due.de:/opt/android/mowesta/'
|
|
}
|
|
} else {
|
|
echo "Skip copying of android bundles for non-master branch."
|
|
}
|
|
|
|
// deploy service to apps pro or apps dev
|
|
if (env.BRANCH_NAME == "master" && release) {
|
|
echo "Deploying to production server ..."
|
|
withCredentials([sshUserPrivateKey(credentialsId: "mowesta-server-key", keyFileVariable: "KEYFILE")]) {
|
|
sh 'scp -i $KEYFILE service-war/build/libs/service-war-' + version + '.war wildfly@apps-pro.nes.uni-due.de:/opt/wildfly-31-mowesta/standalone/deployments/service-war.war'
|
|
sh 'scp -i $KEYFILE web-war/build/libs/web-war-' + version + '.war wildfly@apps-pro.nes.uni-due.de:/opt/wildfly-31-mowesta/standalone/deployments/web-war.war'
|
|
}
|
|
} else if (env.BRANCH_NAME == "master") {
|
|
echo "Deploying to beta server ..."
|
|
withCredentials([sshUserPrivateKey(credentialsId: "mowesta-server-key", keyFileVariable: "KEYFILE")]) {
|
|
sh 'scp -i $KEYFILE service-war/build/libs/service-war-' + version + '.war mowesta@apps-dev.nes.uni-due.de:/home/mowesta/wildfly/standalone/deployments/service-war.war'
|
|
sh 'scp -i $KEYFILE web-war/build/libs/web-war-' + version + '.war mowesta@apps-dev.nes.uni-due.de:/home/mowesta/wildfly/standalone/deployments/web-war.war'
|
|
}
|
|
} else {
|
|
echo "Skipping deployment for non-master branch."
|
|
}
|
|
}
|
|
|
|
}
|