| 1 |
def setCommitStatus(String pStatus, String errorHint = '') { |
| 2 |
switch (pStatus) { |
| 3 |
case 'running': |
| 4 |
pState = 'running' |
| 5 |
pMessage = "" |
| 6 |
break |
| 7 |
case 'success': |
| 8 |
pState = 'success' |
| 9 |
pMessage = ":white_check_mark: ${env.JOB_NAME} :penguin: <b>MEGAchat</b> SUCCEEDED :muscle:<br/>Build results: [Jenkins [${env.BUILD_DISPLAY_NAME}]](${env.RUN_DISPLAY_URL})<br/>Commit: ${env.GIT_COMMIT}" |
| 10 |
break |
| 11 |
case 'aborted': |
| 12 |
pState = 'canceled' |
| 13 |
pMessage = ":interrobang: ${env.JOB_NAME} :penguin: <b>MEGAchat</b> ABORTED :confused:<br/>Build results: [Jenkins [${env.BUILD_DISPLAY_NAME}]](${env.RUN_DISPLAY_URL})<br/>Commit: ${env.GIT_COMMIT}" |
| 14 |
break |
| 15 |
case 'build_failure': |
| 16 |
pState = 'failed' |
| 17 |
pMessage = ":red_circle: ${env.JOB_NAME} :penguin: <b>MEGAchat</b> FAILURE :worried:<br/>Build results: [Jenkins [${env.BUILD_DISPLAY_NAME}]](${env.RUN_DISPLAY_URL})<br/>Commit: ${env.GIT_COMMIT}" |
| 18 |
break |
| 19 |
case 'tests_failure': |
| 20 |
pState = 'failed' |
| 21 |
pMessage = "🟠${env.JOB_NAME} :penguin: <b>MEGAchat</b> FAILURE :worried:<br/>Build results: [Jenkins [${env.BUILD_DISPLAY_NAME}]](${env.RUN_DISPLAY_URL})<br/>Commit: ${env.GIT_COMMIT}" |
| 22 |
break |
| 23 |
case 'unstable': |
| 24 |
pState = 'failed' |
| 25 |
pMessage = ":interrobang: ${env.JOB_NAME} :penguin: <b>MEGAchat</b> UNSTABLE :confused:<br/>Build results: [Jenkins [${env.BUILD_DISPLAY_NAME}]](${env.RUN_DISPLAY_URL})<br/>Commit: ${env.GIT_COMMIT}" |
| 26 |
break |
| 27 |
default: |
| 28 |
pState = 'failed' |
| 29 |
pMessage = ":interrobang: ${env.JOB_NAME} :penguin: <b>MEGAchat</b> UNKNOWN :confused:<br/>Build results: [Jenkins [${env.BUILD_DISPLAY_NAME}]](${env.RUN_DISPLAY_URL})<br/>Commit: ${env.GIT_COMMIT}" |
| 30 |
} |
| 31 |
if (pMessage) { |
| 32 |
if (errorHint) { |
| 33 |
pMessage += '<br/> ' + errorHint |
| 34 |
} |
| 35 |
addGitLabMRComment(comment: pMessage) |
| 36 |
} |
| 37 |
updateGitlabCommitStatus(name: "${PIPELINE_NAME}", state: pState) |
| 38 |
} |
| 39 |
|
| 40 |
def CUSTOM_TIMEOUT |
| 41 |
|
| 42 |
pipeline { |
| 43 |
agent none |
| 44 |
options { |
| 45 |
buildDiscarder(logRotator(numToKeepStr: '135', daysToKeepStr: '21')) |
| 46 |
gitLabConnection('GitLabConnectionJenkins') |
| 47 |
} |
| 48 |
|
| 49 |
environment { |
| 50 |
PIPELINE_NAME = 'Build & test MEGAchat' |
| 51 |
BUILD_OPTIONS = ' ' |
| 52 |
APIURL_TO_TEST = ' ' |
| 53 |
} |
| 54 |
|
| 55 |
stages { |
| 56 |
stage('Update Gitlab commitStatus') { |
| 57 |
agent any |
| 58 |
steps { |
| 59 |
updateGitlabCommitStatus(name: 'Build & test MEGAchat', state: 'running') |
| 60 |
script{ |
| 61 |
COMMIT_ID = env.GIT_COMMIT |
| 62 |
println GIT_COMMIT |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
stage('Build') { |
| 67 |
agent { label 'linux && amd64' } |
| 68 |
stages { |
| 69 |
stage('clean previous runs'){ |
| 70 |
steps{ |
| 71 |
deleteDir() |
| 72 |
} |
| 73 |
} |
| 74 |
stage('Get build parameters'){ |
| 75 |
parallel{ |
| 76 |
stage('Get build options'){ |
| 77 |
steps { |
| 78 |
script{ |
| 79 |
BUILD_OPTIONS = sh(script: 'echo "$gitlabTriggerPhrase" | grep BUILD_OPTIONS | awk -F "BUILD_OPTIONS=" \'{print \$2}\' | cut -d"\\"" -f2 || :', returnStdout: true).trim() |
| 80 |
TESTS_PARALLEL = sh(script: 'echo "$gitlabTriggerPhrase" | grep "\\-\\-sequence" >/dev/null 2>&1 && echo "" || echo "--INSTANCES:10"', returnStdout: true).trim() |
| 81 |
GTEST_REPEAT = sh(script: 'echo "$gitlabTriggerPhrase" | grep --only-matching "\\-\\-gtest_repeat=[^ ]*" | awk -F "gtest_repeat=" \'{print "--gtest_repeat="\$2}\'|| :', returnStdout: true).trim() |
| 82 |
GTEST_FILTER = sh(script: 'echo "$gitlabTriggerPhrase" | grep --only-matching "\\-\\-gtest_filter=[^ ]*" | awk -F "gtest_filter=" \'{print "--gtest_filter="\$2}\'|| :', returnStdout: true).trim() |
| 83 |
CUSTOM_TIMEOUT = sh(script: 'echo "$gitlabTriggerPhrase" | grep --only-matching "\\-\\-timeout=[^ ]*" | awk -F "timeout=" \'{print \$2}\'|| :', returnStdout: true).trim() |
| 84 |
CUSTOM_TIMEOUT = CUSTOM_TIMEOUT? CUSTOM_TIMEOUT : "150" |
| 85 |
println BUILD_OPTIONS |
| 86 |
println TESTS_PARALLEL |
| 87 |
println GTEST_REPEAT |
| 88 |
println GTEST_FILTER |
| 89 |
println CUSTOM_TIMEOUT |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
stage('Get MEGAchat branch'){ |
| 95 |
steps { |
| 96 |
script{ |
| 97 |
env.MEGACHAT_BRANCH = sh(script: 'echo "$gitlabMergeRequestDescription" | grep MEGACHAT_BRANCH_TO_TEST | awk -F "MEGACHAT_BRANCH_TO_TEST=" \'{print \$2}\' | cut -d" " -f1', returnStdout: true).trim() |
| 98 |
if (MEGACHAT_BRANCH == ""){ |
| 99 |
echo "MEGACHAT_BRANCH was not found on description so develop will be used by default" |
| 100 |
env.MEGACHAT_BRANCH = "develop" |
| 101 |
} |
| 102 |
println MEGACHAT_BRANCH |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
stage('Get API URL'){ |
| 108 |
steps { |
| 109 |
script{ |
| 110 |
APIURL_TO_TEST = sh(script: 'echo "$gitlabMergeRequestDescription" | grep USE_APIURL_TO_TEST | awk -F "USE_APIURL_TO_TEST=" \'{print \$2}\' | cut -d" " -f1', returnStdout: true).trim() |
| 111 |
println APIURL_TO_TEST |
| 112 |
if (APIURL_TO_TEST == ""){ |
| 113 |
APIURL_TO_TEST = "https://g.api.mega.co.nz/" |
| 114 |
echo "APIURL_TO_TEST was not found on description so ${APIURL_TO_TEST} will be used by default" |
| 115 |
} |
| 116 |
echo "APIURL_TO_TEST will be ${APIURL_TO_TEST}" |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
stage('Checkout SDK and MEGAchat'){ |
| 125 |
steps { |
| 126 |
//Clone MEGAchat |
| 127 |
sh "echo Cloning MEGAchat branch \"${MEGACHAT_BRANCH}\"" |
| 128 |
checkout([ |
| 129 |
$class: 'GitSCM', |
| 130 |
branches: [[name: "origin/${MEGACHAT_BRANCH}"]], |
| 131 |
userRemoteConfigs: [[ url: "${env.GIT_URL_MEGACHAT}", credentialsId: "12492eb8-0278-4402-98f0-4412abfb65c1" ]], |
| 132 |
extensions: [ |
| 133 |
[$class: "UserIdentity",name: "jenkins", email: "jenkins@jenkins"] |
| 134 |
] |
| 135 |
]) |
| 136 |
dir('third-party/mega'){ |
| 137 |
//Clone SDK (with PreBuildMerge) |
| 138 |
checkout([ |
| 139 |
$class: 'GitSCM', |
| 140 |
branches: [[name: "origin/${env.gitlabSourceBranch}"]], |
| 141 |
userRemoteConfigs: [[ url: "${env.GIT_URL_SDK}", credentialsId: "12492eb8-0278-4402-98f0-4412abfb65c1" ]], |
| 142 |
extensions: [ |
| 143 |
[$class: "UserIdentity",name: "jenkins", email: "jenkins@jenkins"], |
| 144 |
[$class: 'PreBuildMerge', options: [fastForwardMode: 'FF', mergeRemote: "origin", mergeStrategy: 'DEFAULT', mergeTarget: "${env.gitlabTargetBranch}"]] |
| 145 |
] |
| 146 |
]) |
| 147 |
} |
| 148 |
script{ |
| 149 |
megachat_sources_workspace = WORKSPACE |
| 150 |
sdk_sources_workspace = "${megachat_sources_workspace}/third-party/mega" |
| 151 |
} |
| 152 |
} |
| 153 |
post { |
| 154 |
failure { |
| 155 |
script { |
| 156 |
setCommitStatus('build_failure', ':red_circle: Checkout failed') |
| 157 |
} |
| 158 |
echo 'Error: Checkout stage failed' |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
stage('Build MEGAchat'){ |
| 164 |
environment{ |
| 165 |
VCPKGPATH = "/opt/vcpkg" |
| 166 |
VCPKG_BINARY_SOURCES = 'clear;x-aws,s3://vcpkg-cache/archives/,readwrite' |
| 167 |
AWS_ACCESS_KEY_ID = credentials('s4_access_key_id_vcpkg_cache') |
| 168 |
AWS_SECRET_ACCESS_KEY = credentials('s4_secret_access_key_vcpkg_cache') |
| 169 |
AWS_ENDPOINT_URL = "https://s3.g.s4.mega.io" |
| 170 |
BUILD_DIR = "build_dir" |
| 171 |
} |
| 172 |
steps{ |
| 173 |
dir(megachat_sources_workspace){ |
| 174 |
sh "echo Building MEGAchat" |
| 175 |
sh "cmake --preset dev-unix -DCMAKE_BUILD_TYPE=Debug -DVCPKG_ROOT=${VCPKGPATH} ${BUILD_OPTIONS} -DCMAKE_VERBOSE_MAKEFILE=ON \ |
| 176 |
-S ${megachat_sources_workspace} -B ${megachat_sources_workspace}/${BUILD_DIR}" |
| 177 |
sh "cmake --build ${megachat_sources_workspace}/${BUILD_DIR} -j5" |
| 178 |
} |
| 179 |
} |
| 180 |
post { |
| 181 |
failure { |
| 182 |
script { |
| 183 |
setCommitStatus('build_failure', ':red_circle: Build failed. Tests won`t run') |
| 184 |
} |
| 185 |
echo "Error: Build stage failed. Tests won't run." |
| 186 |
} |
| 187 |
} |
| 188 |
} |
| 189 |
stage('Run MEGAchat tests'){ |
| 190 |
environment { |
| 191 |
MEGA_PWD0 = credentials('MEGA_PWD_DEFAULT') |
| 192 |
MEGA_PWD1 = credentials('MEGA_PWD_DEFAULT') |
| 193 |
MEGA_PWD2 = credentials('MEGA_PWD_DEFAULT') |
| 194 |
BUILD_DIR = "build_dir" |
| 195 |
} |
| 196 |
steps{ |
| 197 |
script { |
| 198 |
def lockLabel = '' |
| 199 |
if ("${APIURL_TO_TEST}" == 'https://g.api.mega.co.nz/') { |
| 200 |
lockLabel = 'SDK_Concurrent_Test_Accounts' |
| 201 |
} else { |
| 202 |
lockLabel = 'SDK_Concurrent_Test_Accounts_Staging' |
| 203 |
} |
| 204 |
lock(label: lockLabel, variable: 'ACCOUNTS_COMBINATION', quantity: 1, resourceSelectStrategy: "random", resource: null){ |
| 205 |
dir("${megachat_sources_workspace}"){ |
| 206 |
timeout(time: "${CUSTOM_TIMEOUT}", unit: 'MINUTES') { |
| 207 |
script{ |
| 208 |
env.MEGA_EMAIL0 = "${env.ACCOUNTS_COMBINATION}" |
| 209 |
echo "${env.ACCOUNTS_COMBINATION}" |
| 210 |
|
| 211 |
} |
| 212 |
sh """#!/bin/bash |
| 213 |
set -x |
| 214 |
ulimit -c unlimited |
| 215 |
if [ -z \"${TESTS_PARALLEL}\" ]; then |
| 216 |
# Sequential run |
| 217 |
${env.BUILD_DIR}/tests/sdk_test/megachat_tests --USERAGENT:${env.USER_AGENT_TESTS_MEGACHAT} --APIURL:${APIURL_TO_TEST} ${GTEST_FILTER} ${GTEST_REPEAT} & |
| 218 |
pid=\$! |
| 219 |
wait \$pid || FAILED=1 |
| 220 |
else |
| 221 |
# Parallel run |
| 222 |
${env.BUILD_DIR}/tests/sdk_test/megachat_tests --USERAGENT:${env.USER_AGENT_TESTS_MEGACHAT} --APIURL:${APIURL_TO_TEST} ${GTEST_FILTER} ${GTEST_REPEAT} ${TESTS_PARALLEL} 2>&1 | tee tests.stdout |
| 223 |
[ \"\${PIPESTATUS[0]}\" != \"0\" ] && FAILED=1 |
| 224 |
fi |
| 225 |
|
| 226 |
if [ -n "\$FAILED" ]; then |
| 227 |
if [ -z \"${TESTS_PARALLEL}\" ]; then |
| 228 |
# Sequential run |
| 229 |
coreFiles=\"test_pid_\$pid/core\" |
| 230 |
else |
| 231 |
# Parallel run |
| 232 |
procFailed=`grep \"<< PROCESS\" tests.stdout | sed 's/.*PID:\\([0-9]*\\).*/\\1/'` |
| 233 |
if [ -n \"\$procFailed\" ]; then |
| 234 |
for i in \$procFailed; do |
| 235 |
coreFiles=\"\$coreFiles test_pid_\$i/core\" |
| 236 |
done |
| 237 |
fi |
| 238 |
fi |
| 239 |
fi |
| 240 |
|
| 241 |
if [ -n \"\$coreFiles\" ]; then |
| 242 |
maxTime=10 |
| 243 |
startTime=`date +%s` |
| 244 |
coresProcessed=0 |
| 245 |
coresTotal=`echo \$coreFiles | wc -w` |
| 246 |
# While there are pending cores |
| 247 |
while [ \$coresProcessed -lt \$coresTotal ] && [ \$( expr `date +%s` - \$startTime ) -lt \$maxTime ]; do |
| 248 |
echo "Waiting for core dumps..." |
| 249 |
sleep 1 |
| 250 |
for i in \$coreFiles; do |
| 251 |
if [ -e \"\$i\" ] && [ -z \"\$( lsof \$i 2>/dev/null )\" ]; then |
| 252 |
echo |
| 253 |
echo |
| 254 |
echo \"Processing core dump \$i :: \$(grep `echo \$i | sed 's#test_pid_\\([0-9].*\\)/core#\\1#'` tests.stdout)\" |
| 255 |
echo thread apply all bt > backtrace |
| 256 |
echo quit >> backtrace |
| 257 |
gdb -q ${env.BUILD_DIR}/tests/sdk_test/megachat_tests \$i -x backtrace |
| 258 |
tar rf core.tar \$i |
| 259 |
coresProcessed=`expr \$coresProcessed + 1` |
| 260 |
coreFiles=`echo \$coreFiles | sed -e \"s#\$i##\"` |
| 261 |
fi |
| 262 |
done |
| 263 |
done |
| 264 |
if [ -e core.tar ]; then |
| 265 |
tar rf core.tar -C ${env.BUILD_DIR}/tests/sdk_test/ megachat_tests |
| 266 |
gzip core.tar |
| 267 |
fi |
| 268 |
fi |
| 269 |
|
| 270 |
gzip -c test.log > test_${BUILD_ID}.log.gz || : |
| 271 |
rm test.log || : |
| 272 |
if [ ! -z "\$FAILED" ]; then |
| 273 |
false |
| 274 |
fi |
| 275 |
""" |
| 276 |
} |
| 277 |
} |
| 278 |
} |
| 279 |
} |
| 280 |
} |
| 281 |
post { |
| 282 |
failure { |
| 283 |
script { |
| 284 |
setCommitStatus('tests_failure', ':warning: Build succeed. Tests failed') |
| 285 |
} |
| 286 |
echo 'Error: Test stage failed' |
| 287 |
} |
| 288 |
} |
| 289 |
} |
| 290 |
} |
| 291 |
post{ |
| 292 |
always { |
| 293 |
archiveArtifacts artifacts: 'test*.log*, core.tar.gz', fingerprint: true |
| 294 |
deleteDir() |
| 295 |
} |
| 296 |
} |
| 297 |
} |
| 298 |
} |
| 299 |
post { |
| 300 |
success { |
| 301 |
updateGitlabCommitStatus(name: 'Build & test MEGAchat', state: 'success') |
| 302 |
addGitLabMRComment(comment: ":white_check_mark: ${currentBuild.projectName} :penguin: <b>MEGAchat</b> SUCCEEDED :muscle:<br/>Build results: [Jenkins [${currentBuild.displayName}]](${currentBuild.absoluteUrl})<br/>Commit: ${COMMIT_ID}" ) |
| 303 |
} |
| 304 |
unstable { |
| 305 |
updateGitlabCommitStatus(name: 'Build & test MEGAchat', state: 'failed') |
| 306 |
addGitLabMRComment(comment: ":interrobang: ${currentBuild.projectName} :penguin: <b>MEGAchat</b> UNSTABLE :confused:<br/>Build results: [Jenkins [${currentBuild.displayName}]](${currentBuild.absoluteUrl})<br/>Commit: ${COMMIT_ID}" ) |
| 307 |
} |
| 308 |
aborted { |
| 309 |
updateGitlabCommitStatus(name: 'Build & test MEGAchat', state: 'canceled') |
| 310 |
addGitLabMRComment(comment: ":interrobang: ${currentBuild.projectName} :penguin: <b>MEGAchat</b> ABORTED :confused:<br/>Build results: [Jenkins [${currentBuild.displayName}]](${currentBuild.absoluteUrl})<br/>Commit: ${COMMIT_ID}" ) |
| 311 |
} |
| 312 |
} |
| 313 |
} |