import hudson.model.Result import hudson.model.*; import jenkins.model.CauseOfInterruption node { } def sync_source() { sh ''' hostname date ''' sh ''' cd ${WKC} [ -f src/connector/grafanaplugin/README.md ] && rm -f src/connector/grafanaplugin/README.md > /dev/null || echo "failed to remove grafanaplugin README.md" git reset --hard >/dev/null ''' script { if (env.CHANGE_TARGET == 'master') { sh ''' cd ${WKC} git checkout master ''' } else if (env.CHANGE_TARGET == '2.0') { sh ''' cd ${WKC} git checkout 2.0 ''' } else if (env.CHANGE_TARGET == '2.4') { sh ''' cd ${WKC} git checkout 2.4 ''' } else { sh ''' cd ${WKC} git checkout develop ''' } } sh ''' cd ${WKC} git reset --hard git remote prune origin [ -f src/connector/grafanaplugin/README.md ] && rm -f src/connector/grafanaplugin/README.md > /dev/null || echo "failed to remove grafanaplugin README.md" git pull >/dev/null git fetch origin +refs/pull/${CHANGE_ID}/merge git checkout -qf FETCH_HEAD git reset --hard git clean -dfx git submodule update --init --recursive --remote git submodule update --init --recursive cd ${WK} git reset --hard ''' sh ''' cd ${WKCT} git reset --hard ''' script { if (env.CHANGE_TARGET == 'master') { sh ''' cd ${WK} git checkout master cd ${WKCT} git checkout master ''' } else if (env.CHANGE_TARGET == '2.0') { sh ''' cd ${WK} git checkout 2.0 cd ${WKCT} git checkout 2.0 ''' } else if (env.CHANGE_TARGET == '2.4') { sh ''' cd ${WK} git checkout 2.4 cd ${WKCT} git checkout 2.4 ''' } else { sh ''' cd ${WK} git checkout develop cd ${WKCT} git checkout develop ''' } } sh ''' export TZ=Asia/Harbin cd ${WK} git pull >/dev/null git clean -dfx cd ${WKCT} git pull >/dev/null git clean -dfx date ''' } def pre_test() { sync_source() sh ''' cd ${WK} mkdir -p debug cd debug go env -w GOPROXY=https://goproxy.cn,direct go env -w GO111MODULE=on cmake .. -DBUILD_HTTP=false -DBUILD_TOOLS=true > /dev/null make -j8 >/dev/null ''' return 1 } def pre_test_mac() { sync_source() sh ''' cd ${WK} mkdir -p debug cd debug go env -w GOPROXY=https://goproxy.cn,direct go env -w GO111MODULE=on cmake .. -DBUILD_TOOLS=false > /dev/null make -j8 >/dev/null ''' return 1 } pipeline { agent {label " dispatcher "} options { skipDefaultCheckout() } environment{ WK = '/var/data/jenkins/workspace/TDinternal' WKC = '/var/data/jenkins/workspace/TDinternal/community' WKCT = '/var/data/jenkins/workspace/TDinternal/community/tests' LOGDIR = '/var/data/jenkins/workspace/log' } stages { stage ('pre_build') { steps { sh ''' date pwd env hostname ''' } } stage ('Parallel build stage') { //only build pr options { skipDefaultCheckout() } when { allOf { changeRequest() not { expression { env.CHANGE_BRANCH =~ /docs\// }} } } parallel { stage ('dispatcher sync source') { steps { timeout(time: 20, unit: 'MINUTES') { sync_source() script { sh ''' echo "dispatcher ready" date ''' } } } } stage ('build worker01') { agent {label " worker01 "} steps { timeout(time: 20, unit: 'MINUTES') { pre_test() script { sh ''' echo "worker01 build done" date ''' } } } } stage ('build worker02') { agent {label " worker02 "} steps { timeout(time: 20, unit: 'MINUTES') { pre_test() script { sh ''' echo "worker02 build done" date ''' } } } } stage ('build worker03') { agent {label " worker03 "} steps { timeout(time: 20, unit: 'MINUTES') { pre_test() script { sh ''' echo "worker03 build done" date ''' } } } } stage ('build worker04') { agent {label " worker04 "} steps { timeout(time: 20, unit: 'MINUTES') { pre_test() script { sh ''' echo "worker04 build done" date ''' } } } } stage ('build worker05') { agent {label " worker05 "} steps { timeout(time: 20, unit: 'MINUTES') { pre_test() script { sh ''' echo "worker05 build done" date ''' } } } } } } stage('run test') { options { skipDefaultCheckout() } when { allOf { changeRequest() not { expression { env.CHANGE_BRANCH =~ /docs\// }} } } parallel { stage ('build worker08_arm32') { agent {label " worker08_arm32 "} steps { timeout(time: 20, unit: 'MINUTES') { pre_test() script { sh ''' echo "worker08_arm32 build done" date ''' } } } } stage ('build worker07_arm64') { agent {label " worker07_arm64 "} steps { timeout(time: 20, unit: 'MINUTES') { pre_test() script { sh ''' echo "worker07_arm64 build done" date ''' } } } } stage ('build Mac_catalina ') { agent {label " Mac_catalina "} steps { timeout(time: 20, unit: 'MINUTES') { pre_test_mac() script { sh ''' echo "Mac_catalina build done" date ''' } } } } stage('run cases') { steps { sh ''' date hostname ''' catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { timeout(time: 20, unit: 'MINUTES') { sh ''' date cd ${WKC}/tests/parallel_test time ./run.sh -m m.json -t cases.task -l ${LOGDIR} -b ${BRANCH_NAME} date hostname ''' } } } } } } } post { success { emailext ( subject: "PR-result: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' SUCCESS", body: """
构建信息 |
|
构建信息 |
|