Debian Codegraph @

sdk/jenkinsfile/Jenkinsfile_MR_linux_cmake

raw
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>Linux</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>Linux</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>Linux</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>Linux</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>Linux</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>Linux</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 linux'
51 BUILD_OPTIONS = ''
52 TESTS_PARALLEL = ''
53 APIURL_TO_TEST = ''
54 GTEST_REPEAT = ''
55 GTEST_FILTER = ''
56 }
57
58 stages {
59 stage('Update Gitlab commit status') {
60 agent any
61 steps {
62 updateGitlabCommitStatus(name: 'Build & test linux', state: 'running')
63 script{
64 COMMIT_ID = env.GIT_COMMIT
65 println GIT_COMMIT
66 }
67 }
68 }
69 stage('Build'){
70 agent { label 'linux && amd64' }
71 stages {
72 stage('clean previous runs'){
73 steps{
74 deleteDir()
75 }
76 }
77 stage('Get parameters'){
78 parallel{
79 stage('Get build and run paramters'){
80 steps {
81 script{
82 BUILD_OPTIONS = sh(script: 'echo "$gitlabTriggerPhrase" | grep BUILD_OPTIONS | awk -F "BUILD_OPTIONS=" \'{print \$2}\' | cut -d"\\"" -f2 || :', returnStdout: true).trim()
83 TESTS_PARALLEL = sh(script: 'echo "$gitlabTriggerPhrase" | grep "\\-\\-sequence" >/dev/null 2>&1 && echo "" || echo "--INSTANCES:10"', returnStdout: true).trim()
84 GTEST_REPEAT = sh(script: 'echo "$gitlabTriggerPhrase" | grep --only-matching "\\-\\-gtest_repeat=[^ ]*" | awk -F "gtest_repeat=" \'{print "--gtest_repeat="\$2}\'|| :', returnStdout: true).trim()
85 GTEST_FILTER = sh(script: 'echo "$gitlabTriggerPhrase" | grep --only-matching "\\-\\-gtest_filter=[^ ]*" | awk -F "gtest_filter=" \'{print "--gtest_filter="\$2}\'|| :', returnStdout: true).trim()
86 CUSTOM_TIMEOUT = sh(script: 'echo "$gitlabTriggerPhrase" | grep --only-matching "\\-\\-timeout=[^ ]*" | awk -F "timeout=" \'{print \$2}\'|| :', returnStdout: true).trim()
87 CUSTOM_TIMEOUT = CUSTOM_TIMEOUT? CUSTOM_TIMEOUT : "250"
88 println BUILD_OPTIONS
89 println TESTS_PARALLEL
90 println GTEST_REPEAT
91 println GTEST_FILTER
92 println CUSTOM_TIMEOUT
93 }
94 }
95 }
96
97 stage('Get API URL'){
98 steps {
99 script{
100 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()
101 println APIURL_TO_TEST
102 if (APIURL_TO_TEST == ""){
103 APIURL_TO_TEST = "https://g.api.mega.co.nz/"
104 echo "APIURL_TO_TEST was not found on description so ${APIURL_TO_TEST} will be used by default"
105 }
106 echo "APIURL_TO_TEST will be ${APIURL_TO_TEST}"
107 }
108 }
109 }
110
111 }
112 }
113
114 stage('Checkout Linux'){
115 steps {
116 checkout([
117 $class: 'GitSCM',
118 branches: [[name: "origin/${env.gitlabSourceBranch}"]],
119 userRemoteConfigs: [[ url: "${env.GIT_URL_SDK}", credentialsId: "12492eb8-0278-4402-98f0-4412abfb65c1" ]],
120 extensions: [
121 [$class: "UserIdentity",name: "jenkins", email: "jenkins@jenkins"],
122 [$class: 'PreBuildMerge', options: [fastForwardMode: 'FF', mergeRemote: "origin", mergeStrategy: 'DEFAULT', mergeTarget: "${env.gitlabTargetBranch}"]]
123 ]
124 ])
125 script{
126 linux_sources_workspace = WORKSPACE
127 //linux_build_agent = "${NODE_NAME}"
128 }
129 }
130 post {
131 failure {
132 script {
133 setCommitStatus('build_failure', ':warning: Checkout failed')
134 }
135 echo 'Error: Checkout stage failed'
136 }
137 }
138 }
139 stage('Build Linux'){
140 options{
141 timeout(time: 120, unit: 'MINUTES')
142 }
143 environment{
144 VCPKGPATH = "/opt/vcpkg"
145 BUILD_DIR = "build_dir"
146 VCPKG_BINARY_SOURCES = 'clear;x-aws,s3://vcpkg-cache/archives/,readwrite'
147 AWS_ACCESS_KEY_ID = credentials('s4_access_key_id_vcpkg_cache')
148 AWS_SECRET_ACCESS_KEY = credentials('s4_secret_access_key_vcpkg_cache')
149 AWS_ENDPOINT_URL = "https://s3.g.s4.mega.io"
150 }
151 steps{
152 dir("${linux_sources_workspace}") {
153 sh "rm -rf ${BUILD_DIR}; mkdir ${BUILD_DIR}"
154 //Build SDK
155 sh "echo Building SDK"
156 sh "cmake -DUSE_LIBUV=ON -DENABLE_QT_BINDINGS=ON -DENABLE_JAVA_BINDINGS=ON -DENABLE_CHAT=ON -DENABLE_MEDIA_FILE_METADATA=ON -DWITH_FUSE=1 -DCMAKE_BUILD_TYPE=Debug -DVCPKG_ROOT=${VCPKGPATH} \
157 ${BUILD_OPTIONS} -DCMAKE_VERBOSE_MAKEFILE=ON -S ${linux_sources_workspace} -B ${linux_sources_workspace}/${BUILD_DIR}"
158 sh "cmake --build ${linux_sources_workspace}/${BUILD_DIR} -j5"
159 }
160 }
161 post {
162 failure {
163 script {
164 setCommitStatus('build_failure', ':warning: Build failed. Tests won`t run')
165 }
166 echo "Error: Build stage failed. Tests won't run."
167 }
168 }
169 }
170 stage('Run Linux tests'){
171 environment {
172 MEGA_PWD = credentials('MEGA_PWD_DEFAULT')
173 MEGA_PWD_AUX = credentials('MEGA_PWD_DEFAULT')
174 MEGA_PWD_AUX2 = credentials('MEGA_PWD_DEFAULT')
175 MEGA_REAL_PWD=credentials('MEGA_REAL_PWD_TEST')
176 BUILD_DIR = "build_dir"
177 }
178 steps{
179 timeout(time: "${CUSTOM_TIMEOUT}", unit: 'MINUTES') {
180 script {
181 def lockLabel = ''
182 if ("${APIURL_TO_TEST}" == 'https://g.api.mega.co.nz/') {
183 lockLabel = 'SDK_Concurrent_Test_Accounts'
184 } else {
185 lockLabel = 'SDK_Concurrent_Test_Accounts_Staging'
186 }
187 lock(label: lockLabel, variable: 'ACCOUNTS_COMBINATION', quantity: 1, resourceSelectStrategy: "random", resource: null){
188 dir("${linux_sources_workspace}") {
189 script{
190 env.MEGA_EMAIL = "${env.ACCOUNTS_COMBINATION}"
191 echo "${env.ACCOUNTS_COMBINATION}"
192 }
193 sh "echo Running tests"
194 sh """#!/bin/bash
195 set -x
196 ulimit -c unlimited
197
198 ${env.BUILD_DIR}/tests/unit/test_unit || FAILED=1
199
200 if [ -z \"\$FAILED\" ]; then
201 GFXWORKER_TEST_DIR=${env.BUILD_DIR}/tools/gfxworker/tests/integration/
202 GFXWORKER_TEST_NAME=gfxworker_test_integration
203 GFXWORKER_TEST_PATH=\"\$GFXWORKER_TEST_DIR\$GFXWORKER_TEST_NAME\"
204 if [ -f \"\$GFXWORKER_TEST_PATH\" ]; then
205 \$GFXWORKER_TEST_PATH || FAILED=2
206 gzip -c gfxworker_test_integration.log > gfxworker_test_integration_${BUILD_ID}.log.gz || :
207 rm gfxworker_test_integration.log || :
208 fi
209 fi
210
211 if [ -z \"\$FAILED\" ]; then
212 if [ -z \"${TESTS_PARALLEL}\" ]; then
213 # Sequential run
214 ${env.BUILD_DIR}/tests/integration/test_integration --FREEACCOUNTS --CI --USERAGENT:${env.USER_AGENT_TESTS_SDK} --APIURL:${APIURL_TO_TEST} ${GTEST_FILTER} ${GTEST_REPEAT} &
215 pid=\$!
216 wait \$pid || FAILED=3
217 if [ \"\$FAILED\" = \"3\" ]; then
218 cp ${linux_sources_workspace}/pid_\$pid/test_integration.log .
219 fi
220 else
221 # Parallel run
222 ${env.BUILD_DIR}/tests/integration/test_integration --FREEACCOUNTS --CI --USERAGENT:${env.USER_AGENT_TESTS_SDK} --APIURL:${APIURL_TO_TEST} ${GTEST_FILTER} ${GTEST_REPEAT} ${TESTS_PARALLEL} 2>&1 | tee tests.stdout
223 [ \"\${PIPESTATUS[0]}\" != \"0\" ] && FAILED=3
224 fi
225 fi
226 if [ -n \"\$FAILED\" ]; then
227 if [ \"\$FAILED\" -le 2 ]; then
228 coreFiles=core
229 else # FAILED=3
230 if [ -z \"${TESTS_PARALLEL}\" ]; then
231 # Sequential run
232 coreFiles=\"pid_\$pid/core\"
233 else
234 # Parallel run
235 procFailed=`grep \"<< PROCESS\" tests.stdout | sed 's/.*PID:\\([0-9]*\\).*/\\1/'`
236 if [ -n \"\$procFailed\" ]; then
237 # Parallel run
238 for i in \$procFailed; do
239 coreFiles=\"\$coreFiles pid_\$i/core\"
240 done
241 fi
242 fi
243 fi
244 if [ -n \"\$coreFiles\" ]; then
245 maxTime=10
246 startTime=`date +%s`
247 coresProcessed=0
248 coresTotal=`echo \$coreFiles | wc -w`
249 # While there are pending cores
250 while [ \$coresProcessed -lt \$coresTotal ] && [ \$( expr `date +%s` - \$startTime ) -lt \$maxTime ]; do
251 echo "Waiting for core dumps..."
252 sleep 1
253 for i in \$coreFiles; do
254 if [ -e \"\$i\" ] && [ -z \"\$( lsof \$i 2>/dev/null )\" ]; then
255 echo \"Processing core dump \$i :: \$(grep `echo \$i | sed 's#pid_\\([0-9].*\\)/core#\\1#'` tests.stdout)\"
256 echo thread apply all bt > backtrace
257 echo quit >> backtrace
258 [ \"\$FAILED\" = \"1\" ] && gdb -q ${env.BUILD_DIR}/tests/unit/test_unit \$i -x backtrace
259 [ \"\$FAILED\" = \"2\" ] && gdb -q \$GFXWORKER_TEST_PATH \$i -x backtrace
260 [ \"\$FAILED\" = \"3\" ] && gdb -q ${env.BUILD_DIR}/tests/integration/test_integration \$i -x backtrace
261 tar rf core.tar \$i
262 coresProcessed=`expr \$coresProcessed + 1`
263 coreFiles=`echo \$coreFiles | sed -e \"s#\$i##\"`
264 fi
265 done
266 done
267 if [ -e core.tar ]; then
268 [ \"\$FAILED\" = \"1\" ] && tar rf core.tar -C ${env.BUILD_DIR}/tests/unit/ test_unit
269 [ \"\$FAILED\" = \"2\" ] && tar rf core.tar -C \$GFXWORKER_TEST_DIR \$GFXWORKER_TEST_NAME
270 [ \"\$FAILED\" = \"3\" ] && tar rf core.tar -C ${env.BUILD_DIR}/tests/integration/ test_integration
271 gzip core.tar
272 fi
273 fi
274 fi
275
276 gzip -c test_integration.log > test_integration_${BUILD_ID}.log.gz || :
277 rm test_integration.log || :
278 if [ -n \"\$FAILED\" ]; then
279 exit \"\$FAILED\"
280 fi
281 """
282 }
283 }
284 }
285 }
286 }
287 post {
288 always {
289 dir("${env.WORKSPACE}/src/fuse/supported/platform/posix/scripts") {
290 println "Attempting to clean up any stale MEGA-FS mounts"
291 sh "./cleanup.sh '${env.WORKSPACE}'"
292 }
293 }
294 failure {
295 script {
296 setCommitStatus('tests_failure', ':warning: Build succeed. Tests failed')
297 }
298 echo 'Error: Test stage failed'
299 }
300 }
301 }
302 }
303 post{
304 always {
305 dir("${env.WORKSPACE}/src/fuse/supported/platform/posix/scripts") {
306 echo "Final cleanup of any stale MEGA-FS mounts"
307 sh "./cleanup.sh '${env.WORKSPACE}'"
308 }
309 archiveArtifacts artifacts: '*test_integration*, core.tar.gz', fingerprint: true
310 deleteDir()
311 }
312 }
313 }
314 }
315 post {
316 success {
317 updateGitlabCommitStatus(name: 'Build & test linux', state: 'success')
318 addGitLabMRComment(comment: ":white_check_mark: ${currentBuild.projectName} :penguin: <b>Linux</b> SUCCEEDED :muscle:<br/>Build results: [Jenkins [${currentBuild.displayName}]](${currentBuild.absoluteUrl})<br/>Commit: ${COMMIT_ID}" )
319 }
320 unstable {
321 updateGitlabCommitStatus(name: 'Build & test linux', state: 'failed')
322 addGitLabMRComment(comment: ":interrobang: ${currentBuild.projectName} :penguin: <b>Linux</b> UNSTABLE :confused:<br/>Build results: [Jenkins [${currentBuild.displayName}]](${currentBuild.absoluteUrl})<br/>Commit: ${COMMIT_ID}" )
323 }
324 aborted {
325 updateGitlabCommitStatus(name: 'Build & test linux', state: 'canceled')
326 addGitLabMRComment(comment: ":interrobang: ${currentBuild.projectName} :penguin: <b>Linux</b> ABORTED :confused:<br/>Build results: [Jenkins [${currentBuild.displayName}]](${currentBuild.absoluteUrl})<br/>Commit: ${COMMIT_ID}" )
327 }
328 }
329 }