Jenkins流水线门禁扫描示例代码
提供源码迁移、64位运行模式检查示例代码:
pipeline { agent any options { timeout(time: 1, unit: 'HOURS') } parameters { string(name: 'GIT_URL', defaultValue: 'https://gitee.com/devkit-pipeline/c_demo.git', description: '--> git url <--') string(name: 'GIT_BRANCH', defaultValue: 'master', description: '--> code branch <--') string(name: 'GIT_TARGET_DIR_NAME', defaultValue: 'c_demo', description: '--> code branch <--') } stages{ stage('Git Code') { agent { label 'kunpeng_scanner' //对应添加节点时的标签,可选择多个 } steps { echo '====== 获取源码 ======' checkout scmGit(branches: [[name: "${params.GIT_BRANCH}"]], browser: github("${params.GIT_URL}"), extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: "${params.GIT_TARGET_DIR_NAME}"], cleanBeforeCheckout(deleteUntrackedNestedRepositories: true)], userRemoteConfigs: [[url: "${params.GIT_URL}"]]) } } stage('PARALLEL BUILD') { parallel { stage('Kunpeng') { agent { label 'kunpeng_scanner' } stages{ stage('source-code-migration') { steps { echo '====== 源码迁移 ======' sh ''' if [ ! -d "./report_dir" ]; then mkdir -p ./report_dir; fi /usr/bin/rm -rf ./report_dir/*.html''' script{ def SRC_MIG_STATUS_CODE = sh(returnStatus: true, script: 'devkit porting src-mig -i ./c_demo -c make -r html -o ./report_dir || [ $? -eq 5 ] && echo "有必须要修改的意见"') switch(SRC_MIG_STATUS_CODE) { case 0: currentBuild.result = 'SUCCESS' echo '【源码迁移】--> 无扫描建议 <--' break case 1: currentBuild.result = 'UNSTABLE' echo '【源码迁移】--> 扫描结果仅存在建议项 <--' break case 5: currentBuild.result = 'FAILURE' echo '【源码迁移】--> 扫描结果存在必须修改项 <--' break case 3: currentBuild.result = 'ABORTED' echo '【源码迁移】--> 扫描结果超时 <--' break case 4: currentBuild.result = 'ABORTED' echo '【源码迁移】--> 扫描命令错误 <--' break default: currentBuild.result = 'ABORTED' echo '【源码迁移】--> 异常终止{Ctrl + C | Ctrl + Z} <--' break } } sh 'mv ./report_dir/src-mig*.html ./report_dir/SourceCodeScanningReport.html' } post { always { publishHTML(target: [allowMissing: false, alwaysLinkToLastBuild: false, keepAll : true, reportDir : './report_dir', reportFiles : 'SourceCodeScanningReport.html', reportName : 'Source Code Scanning Report'] ) } } } stage('64-bit-running-mode-check') { steps { echo '====== 64位运行模式 ======' sh ''' if [ ! -d "./report_dir" ]; then mkdir -p ./report_dir; fi /usr/bin/rm -rf ./report_dir/*.html devkit advisor run-mode -i ./c_demo -c make -r html -o ./report_dir mv ./report_dir/mode_check*.html ./report_dir/64-bit-running-mode-check.html ''' } post { always { publishHTML(target: [allowMissing: false, alwaysLinkToLastBuild: false, keepAll : true, reportDir : './report_dir', reportFiles : '64-bit-running-mode-check.html', reportName : '64-bit-running-mode-check Report'] ) } } } } } } } } }
父主题: 门禁检查