Jenkins流水线门禁扫描示例代码
示例代码如下:
pipeline {
agent any
options {
timeout(time: 1, unit: 'HOURS')
}
parameters {
string(name: 'GIT_URL', defaultValue: 'https://github.com/ruanjue/wtdbg2.git', description: '--> git url <--')
string(name: 'GIT_BRANCH', defaultValue: 'v2.5', description: '--> code branch <--')
string(name: 'GIT_TARGET_DIR_NAME', defaultValue: 'wtdbg2', 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 home/TestData/wtdbg2-2.5 -c make -r html -o ./report_dir')
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('vectorized-check') {
steps {
echo '====== 向量化检查 ======'
sh '''
if [ ! -d "./report_dir" ]; then mkdir -p ./report_dir; fi
/usr/bin/rm -rf ./report_dir/*.html
mkdir -p /home/advisor/bc_file
devkit advisor bc-gen -i /home/testcase/cplusproject -c make -o /home/advisor/bc_file
devkit advisor vec-check -i /home/testcase/cplusproject -f /home/advisor/bc_file -c make -r html -o ./report_dir
mv ./report_dir/vec-check*.html ./report_dir/vectorized-check.html
'''
}
post {
always {
publishHTML(target: [allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll : true,
reportDir : './report_dir',
reportFiles : 'vectorized-check.html',
reportName : 'vectorized-check Report']
)
}
}
}
}
}
}
}
}
}
- “home/TestData/wtdbg2-2.5”指待扫描源码的文件夹或压缩包路径,请根据实际情况进行替换。
- “/home/testcase/cplusproject”指BC文件对应的源码文件夹路径,请根据实际情况进行替换。
- “/home/advisor/bc_file”指BC文件路径,请根据实际情况进行替换。
父主题: 门禁检查