Sample Code for Jenkins Pipeline Gated Check-in Scanning
Sample code for source code porting and 64-bit running mode check:
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' //This is the label used when a node is added. Multiple labels may be selected.
}
steps {
echo '====== Obtaining the source code ======'
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 '====== Source code porting ======'
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 "There are issues that must be revised."')
switch(SRC_MIG_STATUS_CODE) {
case 0:
currentBuild.result = 'SUCCESS'
echo '[Source Code Porting]--> No scanning suggestions <--'
break
case 1:
currentBuild.result = 'UNSTABLE'
echo '[Source Code Porting] --> The scan result contains only suggestion items <--'
break
case 5:
currentBuild.result = 'FAILURE'
echo '[Source Code Porting] --> The scan result contains items that must be modified. <--'
break
case 3:
currentBuild.result = 'ABORTED'
echo '[Source Code Porting]--> Scan result timeout <--'
break
case 4:
currentBuild.result = 'ABORTED'
echo '[Source Code Porting]--> Incorrect scanning command <--'
break
default:
currentBuild.result = 'ABORTED'
echo '[Source Code Porting]--> Abnormally terminated {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-bit running mode check======'
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']
)
}
}
}
}
}
}
}
}
}
Parent topic: Gated Check-in