pipeline { agent { kubernetes { inheritFrom 'build-docker code-scan xuanim' } } environment { ZENTAO_VERSION = """${sh( returnStdout: true, script: 'cat VERSION' ).trim()}""" MIDDLE_IMAGE_REPO = 'hub.qc.oop.cc/zentao-ztf' MIDDLE_IMAGE_TAG = """${sh( returnStdout: true, script: 'echo $BUILD_ID-${GIT_COMMIT}' ).trim()}""" XIM_USERS = "" XIM_GROUPS = "" } stages { stage('checkout code') { steps { echo 'checkout code success' sh 'env' } } stage('build quality') { parallel { stage('SonarQube') { steps { container('sonar') { withSonarQubeEnv('sonarqube') { catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { sh 'git config --global --add safe.directory $(pwd)' sh 'sonar-scanner -Dsonar.analysis.user=$(git show -s --format=%ae)' } } } } post { success { container('xuanimbot') { sh 'git config --global --add safe.directory $(pwd)' sh '/usr/local/bin/xuanimbot --title "sonar scanner" --url "https://sonar.qc.oop.cc/dashboard?id=zentaopms&branch=${GIT_BRANCH#*/}" --content "sonar scanner success" --debug --custom' } } failure { container('xuanimbot') { sh 'git config --global --add safe.directory $(pwd)' sh '/usr/local/bin/xuanimbot --title "sonar scanner" --url "https://sonar.qc.oop.cc/dashboard?id=zentaopms&branch=${GIT_BRANCH#*/}" --content "sonar scanner failure" --debug --custom' } } } } stage('Unit Test') { stages { stage('Build Image') { steps { container('docker') { sh 'docker build --pull . -f Dockerfile.test --build-arg VERSION=${ZENTAO_VERSION} --build-arg MIRROR=true -t ${MIDDLE_IMAGE_REPO}:${MIDDLE_IMAGE_TAG}' sh 'docker push ${MIDDLE_IMAGE_REPO}:${MIDDLE_IMAGE_TAG}' } } post { success { echo 'build image success' } failure { container('xuanimbot') { sh 'git config --global --add safe.directory $(pwd)' sh '/usr/local/bin/xuanimbot --users "$(git show -s --format=%ae)" --title "build image" --url "${RUN_DISPLAY_URL}" --content "Build unit test image failure" --debug --custom' } } } } stage('Run') { agent { kubernetes { inheritFrom 'xuanim' containerTemplate { name 'zentao' image "${MIDDLE_IMAGE_REPO}:${MIDDLE_IMAGE_TAG}" command "/usr/bin/entrypoint.sh" } } } options { skipDefaultCheckout() } environment { DATA_REPORT_TOKEN = credentials('data_report_token') } steps { container('zentao') { sh 'rm -f /bin/sh && ln -s /bin/bash /bin/sh' sh ''' . /etc/s6/s6-init/envs . /opt/easysoft/scripts/libmysql.sh wait_for_mysql && initdb.php > /apps/zentao/unittestdb /apps/zentao/test/runtime/ztf /apps/zentao/module -C 11 | tee /apps/zentao/test/${MIDDLE_IMAGE_TAG}.log chmod -R 777 /root parsehtml.php initdb.php /apps/zentao/unittestdb''' publishHTML (target : [allowMissing: false,alwaysLinkToLastBuild: false,keepAll: true,reportDir: 'coverage',reportFiles: 'index.html',reportName: 'UT Coverage Report',reportTitles: 'UT Coverage Report']) sh 'pipeline-unittest.sh /apps/zentao/test/${MIDDLE_IMAGE_TAG}.log' } } post { success { container('xuanimbot') { sh 'git config --global --add safe.directory /home/jenkins/agent/workspace/pangu_pangu_xuanimbot_master' sh '/usr/local/bin/xuanimbot --title "unittest" --url "${RUN_DISPLAY_URL}" --content "Unit test passed" --debug --custom' } } failure { container('xuanimbot') { sh 'git config --global --add safe.directory $(pwd)' sh '/usr/local/bin/xuanimbot --title "unittest" --url "${RUN_DISPLAY_URL}" --content "Unit test failed" --debug --custom' } } } } } }//End unittest } } }// End Root Stages } // End pipeline