From 2a2a49bc72b20471efa55a5d7fba29981e50670c Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Thu, 28 Nov 2024 10:12:39 +0100 Subject: [PATCH 1/5] Change Jenkinsfile to print env variables --- Jenkinsfile | 148 ++++------------------------------------------------ 1 file changed, 9 insertions(+), 139 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index aea4792f82..0eed555653 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,149 +17,19 @@ pipeline { } stages { - stage('Change to JAVA 17') { + stage('Print env variables') { steps { script { - echo 'Changing JAVA version to 17' - sh 'sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java' - env.JAVA_HOME = '/usr/lib/jvm/java-17-openjdk-amd64' + echo $cron_string + echo cron_string + echo JOB_NAME + echo env.JOB_NAME + echo $JOB_NAME + echo JOB_BASE_NAME + echo env.JOB_BASE_NAME + echo $JOB_BASE_NAME } } } - stage('Lint Check') { - steps { - script { - echo 'Running Ktlint' - sh './gradlew ktlintCheck' - } - } - } - stage('Unit tests') { - environment { - ANDROID_HOME = '/opt/android-sdk' - } - steps { - script { - echo 'Running unit tests on app module' - sh './gradlew :app:testDhisDebugUnitTest --stacktrace --no-daemon' - echo 'Running unit tests on all other modules' - sh './gradlew testDebugUnitTest --stacktrace --no-daemon' - } - } - } - stage('Build Test APKs') { - steps { - script { - echo 'Building UI APKs' - sh './gradlew :app:assembleDhisUITestingDebug :app:assembleDhisUITestingDebugAndroidTest :compose-table:assembleAndroidTest :form:assembleAndroidTest' - } - } - } - stage('Run tests') { - parallel { - stage('Deploy and run Form Tests') { - environment { - BROWSERSTACK = credentials('android-browserstack') - form_apk = sh(returnStdout: true, script: 'find form/build/outputs -iname "*.apk" | sed -n 1p') - form_apk_path = "${env.WORKSPACE}/${form_apk}" - buildTag = "${env.GIT_BRANCH} - form" - } - steps { - dir("${env.WORKSPACE}/scripts"){ - script { - echo 'Browserstack deployment and running Form module tests' - sh 'chmod +x browserstackJenkinsForm.sh' - sh './browserstackJenkinsForm.sh' - } - } - } - } - stage('Deploy compose-table module Tests') { - environment { - BROWSERSTACK = credentials('android-browserstack') - compose_table_apk = sh(returnStdout: true, script: 'find compose-table/build/outputs -iname "*.apk" | sed -n 1p') - compose_table_apk_path = "${env.WORKSPACE}/${compose_table_apk}" - buildTag = "${env.GIT_BRANCH} - table" - } - steps { - dir("${env.WORKSPACE}/scripts"){ - script { - echo 'Browserstack deployment and running compose-table module tests' - sh 'chmod +x browserstackJenkinsCompose.sh' - sh './browserstackJenkinsCompose.sh' - } - } - } - } - stage('Deploy and Run UI Tests') { - environment { - BROWSERSTACK = credentials('android-browserstack') - app_apk = sh(returnStdout: true, script: 'find app/build/outputs -iname "*.apk" | sed -n 1p') - test_apk = sh(returnStdout: true, script: 'find app/build/outputs -iname "*.apk" | sed -n 2p') - app_apk_path = "${env.WORKSPACE}/${app_apk}" - test_apk_path = "${env.WORKSPACE}/${test_apk}" - buildTag = "${env.GIT_BRANCH}" - } - steps { - dir("${env.WORKSPACE}/scripts"){ - script { - echo 'Browserstack deployment and running tests' - sh 'chmod +x browserstackJenkins.sh' - sh './browserstackJenkins.sh' - } - } - } - } - } - } - stage('JaCoCo report') { - steps { - script { - echo 'Running JaCoCo report on app module' - sh './gradlew jacocoReport --stacktrace --no-daemon' - } - } - } - stage('Sonarqube') { - environment { - GIT_BRANCH = "${env.GIT_BRANCH}" - // Jenkinsfile considers empty value ('') as null - GIT_BRANCH_DEST = "${env.CHANGE_TARGET == null ? '' : env.CHANGE_TARGET}" - PULL_REQUEST = "${env.CHANGE_ID == null ? '' : env.CHANGE_ID }" - SONAR_TOKEN = credentials('android-sonarcloud-token') - } - steps { - script { - echo 'Running Sonarqube' - sh 'chmod +x ./scripts/sonarqube.sh' - sh './scripts/sonarqube.sh' - } - } - } - - } - post { - success { - sendNotification(env.GIT_BRANCH, '*Build Succeeded*\n', 'good') - } - - failure { - sendNotification(env.GIT_BRANCH, '*Build Failed*\n', 'bad') - } } } - -def sendNotification(String branch, String messagePrefix, String color){ - if( !branch.startsWith('PR') ){ - slackSend channel: '#android-capture-app-ci', color: color, message: messagePrefix+ custom_msg() - } -} - -def custom_msg(){ - def BUILD_URL= env.BUILD_URL - def JOB_NAME = env.JOB_NAME - def BUILD_ID = env.BUILD_ID - def BRANCH_NAME = env.GIT_BRANCH - def JENKINS_LOG= "*Job:* $JOB_NAME\n *Branch:* $BRANCH_NAME\n *Build Number:* $BUILD_NUMBER (<${BUILD_URL}|Open>)" - return JENKINS_LOG -} From d5b0d901e975d6aeca3988a3d0607d50d15525a7 Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Thu, 28 Nov 2024 10:19:46 +0100 Subject: [PATCH 2/5] Modify accessor --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0eed555653..4fa5618dfe 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -20,7 +20,7 @@ pipeline { stage('Print env variables') { steps { script { - echo $cron_string + echo "$cron_string" echo cron_string echo JOB_NAME echo env.JOB_NAME From a9b13b9cdafdc0ee8f255198fe6fb0964e691c72 Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Thu, 28 Nov 2024 10:24:51 +0100 Subject: [PATCH 3/5] Modify accessor --- Jenkinsfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4fa5618dfe..f3b91f34af 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,10 +24,8 @@ pipeline { echo cron_string echo JOB_NAME echo env.JOB_NAME - echo $JOB_NAME echo JOB_BASE_NAME echo env.JOB_BASE_NAME - echo $JOB_BASE_NAME } } } From bdbf40cda205721237202598087b3f895212d39f Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Thu, 28 Nov 2024 12:27:58 +0100 Subject: [PATCH 4/5] Change condition --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index f3b91f34af..2a96543f0f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ //Sets cron schedule just for PUSH job -String cron_string = JOB_NAME == 'android-multibranch-PUSH' ? '0 0 * * *' : '' +String cron_string = JOB_NAME.startsWith('android-multibranch-PUSH') ? '0 0 * * *' : '0 0 0 0 0' pipeline { agent { From ad314a429e4e24fe68a8887a5a16c2b639d23cf7 Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Thu, 28 Nov 2024 12:31:59 +0100 Subject: [PATCH 5/5] Change condition --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2a96543f0f..62d408aaac 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ //Sets cron schedule just for PUSH job -String cron_string = JOB_NAME.startsWith('android-multibranch-PUSH') ? '0 0 * * *' : '0 0 0 0 0' +String cron_string = JOB_NAME.startsWith('android-multibranch-PUSH') ? '0 0 * * *' : '0 0 1 1 1' pipeline { agent {