|
| 1 | +#!groovy |
| 2 | + |
| 3 | +pipeline { |
| 4 | + agent { |
| 5 | + dockerfile { |
| 6 | + filename 'Dockerfile.jenkins' |
| 7 | + // 'docker build' would normally copy the whole build-dir to the container, changing the |
| 8 | + // docker build directory avoids that overhead |
| 9 | + dir 'docker' |
| 10 | + // Pass the uid and the gid of the current user (jenkins-user) to the Dockerfile, so a |
| 11 | + // corresponding user can be added. This is needed to provide the jenkins user inside |
| 12 | + // the container for the ssh-agent to work. |
| 13 | + // Another way would be to simply map the passwd file, but would spoil additional information |
| 14 | + additionalBuildArgs '--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g)' |
| 15 | + args "--device /dev/kvm:/dev/kvm -v /var/local/container_shared/gradle/:/.gradle -v /var/local/container_shared/android-sdk:/usr/local/android-sdk -v /var/local/container_shared/android-home:/.android -v /var/local/container_shared/emulator_console_auth_token:/.emulator_console_auth_token -v /var/local/container_shared/analytics.settings:/analytics.settings" |
| 16 | + } |
| 17 | + } |
| 18 | + |
| 19 | + environment { |
| 20 | + //////// Define environment variables to point to the correct locations inside the container //////// |
| 21 | + //////////// Most likely not edited by the developer |
| 22 | + ANDROID_SDK_ROOT = "/usr/local/android-sdk" |
| 23 | + // Deprecated: Still used by the used gradle version, once gradle respects ANDROID_SDK_ROOT, this can be removed |
| 24 | + ANDROID_HOME = "/usr/local/android-sdk" |
| 25 | + ANDROID_SDK_HOME = "/" |
| 26 | + // Needed for compatibiliby to current Jenkins-wide Envs. Can be removed, once all builds are migrated to Pipeline |
| 27 | + ANDROID_SDK_LOCATION = "/usr/local/android-sdk" |
| 28 | + ANDROID_NDK = "" |
| 29 | + // This is important, as we want the keep our gradle cache, but we can't share it between containers |
| 30 | + // the cache could only be shared if the gradle instances could comunicate with each other |
| 31 | + // imho keeping the cache per executor will have the least space impact |
| 32 | + GRADLE_USER_HOME = "/.gradle/${env.EXECUTOR_NUMBER}" |
| 33 | + // Otherwise user.home returns ? for java applications |
| 34 | + JAVA_TOOL_OPTIONS = "-Duser.home=/tmp/" |
| 35 | + |
| 36 | + //// jenkins-android-helper related variables |
| 37 | + // set to any value to debug jenkins_android* scripts |
| 38 | + ANDROID_EMULATOR_HELPER_DEBUG = "" |
| 39 | + // get stdout of called subprocesses immediately |
| 40 | + PYTHONUNBUFFERED = "true" |
| 41 | + |
| 42 | + //////// Build specific variables //////// |
| 43 | + //////////// May be edited by the developer on changing the build steps |
| 44 | + // modulename |
| 45 | + GRADLE_PROJECT_MODULE_NAME = "catroid" |
| 46 | + |
| 47 | + // APK build output locations |
| 48 | + APK_LOCATION_DEBUG = "${env.GRADLE_PROJECT_MODULE_NAME}/build/outputs/apk/catroid/debug/catroid-catroid-debug.apk" |
| 49 | + APK_LOCATION_STANDALONE = "${env.GRADLE_PROJECT_MODULE_NAME}/build/outputs/apk/standalone/debug/catroid-standalone-debug.apk" |
| 50 | + |
| 51 | + // share.catrob.at |
| 52 | + CATROBAT_SHARE_UPLOAD_BRANCH = "develop" |
| 53 | + CATROBAT_SHARE_APK_NAME = "org.catrobat.catroid_debug_${env.CATROBAT_SHARE_UPLOAD_BRANCH}_latest.apk" |
| 54 | + } |
| 55 | + |
| 56 | + options { |
| 57 | + timeout(time: 2, unit: 'HOURS') |
| 58 | + timestamps() |
| 59 | + } |
| 60 | + |
| 61 | + stages { |
| 62 | + stage('Setup Android SDK') { |
| 63 | + steps { |
| 64 | + // Install Android SDK |
| 65 | + lock("update-android-sdk-on-${env.NODE_NAME}") { |
| 66 | + sh "./buildScripts/build_step_install_android_sdk" |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + stage('Static Analysis') { |
| 72 | + steps { |
| 73 | + sh "./buildScripts/build_step_run_static_analysis" |
| 74 | + } |
| 75 | + |
| 76 | + post { |
| 77 | + always { |
| 78 | + pmd canComputeNew: false, canRunOnFailed: true, defaultEncoding: '', healthy: '', pattern: "${env.GRADLE_PROJECT_MODULE_NAME}/build/reports/pmd.xml", unHealthy: '', unstableTotalAll: '0' |
| 79 | + checkstyle canComputeNew: false, canRunOnFailed: true, defaultEncoding: '', healthy: '', pattern: "${env.GRADLE_PROJECT_MODULE_NAME}/build/reports/checkstyle.xml", unHealthy: '', unstableTotalAll: '0' |
| 80 | + androidLint canComputeNew: false, canRunOnFailed: true, defaultEncoding: '', healthy: '', pattern: "${env.GRADLE_PROJECT_MODULE_NAME}/build/reports/lint*.xml", unHealthy: '', unstableTotalAll: '0' |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + stage('Unit and Device tests') { |
| 86 | + steps { |
| 87 | + // Run local unit tests |
| 88 | + sh "./buildScripts/build_step_run_unit_tests__all_tests" |
| 89 | + // ensure that the following test run does not overwrite the results |
| 90 | + sh "mv ${env.GRADLE_PROJECT_MODULE_NAME}/build ${env.GRADLE_PROJECT_MODULE_NAME}/build-unittest" |
| 91 | + |
| 92 | + // Run device tests for package: org.catrobat.catroid.test |
| 93 | + sh "./buildScripts/build_step_run_tests_on_emulator__test_pkg" |
| 94 | + // ensure that the following test run does not overwrite the results |
| 95 | + sh "mv ${env.GRADLE_PROJECT_MODULE_NAME}/build ${env.GRADLE_PROJECT_MODULE_NAME}/build-test-test-pkg" |
| 96 | + |
| 97 | + // Run device tests for class: org.catrobat.catroid.uiespresso.testsuites.PullRequestTriggerSuite |
| 98 | + sh "./buildScripts/build_step_run_tests_on_emulator__pr_test_suite" |
| 99 | + } |
| 100 | + |
| 101 | + post { |
| 102 | + always { |
| 103 | + junit '**/*TEST*.xml' |
| 104 | + |
| 105 | + // stop/kill emulator |
| 106 | + sh "./buildScripts/build_helper_stop_emulator" |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + stage('Standalone-APK') { |
| 112 | + // It checks that the creation of standalone APKs (APK for a Pocketcode app) works, reducing the risk of breaking gradle changes. |
| 113 | + // The resulting APK is not verified itself. |
| 114 | + steps { |
| 115 | + sh "./buildScripts/build_step_create_standalone_apk" |
| 116 | + archiveArtifacts "${env.APK_LOCATION_STANDALONE}" |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + stage('Independent-APK') { |
| 121 | + // It checks that the job builds with the parameters to have unique APKs, reducing the risk of breaking gradle changes. |
| 122 | + // The resulting APK is not verified on itself. |
| 123 | + steps { |
| 124 | + sh "./buildScripts/build_step_create_independent_apk" |
| 125 | + stash name: "apk-independent", includes: "${env.APK_LOCATION_DEBUG}" |
| 126 | + archiveArtifacts "${env.APK_LOCATION_DEBUG}" |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + stage('Upload to share') { |
| 131 | + when { |
| 132 | + branch "${env.CATROBAT_SHARE_UPLOAD_BRANCH}" |
| 133 | + } |
| 134 | + |
| 135 | + steps { |
| 136 | + unstash "apk-independent" |
| 137 | + script { |
| 138 | + uploadFileToShare "${env.APK_LOCATION_DEBUG}", "${env.CATROBAT_SHARE_APK_NAME}" |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + post { |
| 145 | + always { |
| 146 | + step([$class: 'LogParserPublisher', failBuildOnError: true, projectRulePath: 'buildScripts/log_parser_rules', unstableOnWarning: true, useProjectRule: true]) |
| 147 | + |
| 148 | + // Send notifications with standalone=false |
| 149 | + script { |
| 150 | + sendNotifications false |
| 151 | + } |
| 152 | + } |
| 153 | + } |
| 154 | +} |
0 commit comments