Jenkins流水线代码示例
提供扫描、编译、测试相关能力的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') {
steps {
node('kunpeng_scanner') {
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}"]])
}
node('kunpeng_c_builder_gcc') {
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
devkit porting src-mig -i ./wtdbg2 -c make -r html -o ./report_dir
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
devkit advisor vec-check -i ../src/test-gllvm -f ../src/test-gllvm -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']
)
}
}
}
stage('A-FOT') {
agent {
label 'kunpeng_c_builder_gcc'
}
steps{
// 安装部署完成后已有GCC for openEuler的环境,请先执行与x86平台一致的编译命令
cd /path/to/repository
make
sh 'a-fot --config_file a-fot.ini'
}
}
stage('compatibility testing') {
steps {
script{
echo '====== compatibility testing ======'
sh '''
if [ ! -d "./report_dir" ]; then mkdir -p ./report_dir; fi
/usr/bin/rm -rf ./report_dir/*.html
/bin/cp -rf /xxx/compatibility_testing/template.html.bak /xxx/compatibility_testing/template.html
sudo /bin/bash /xxx/compatibility_testing/bin/compatibility_test
/bin/cp -rf /xxx/compatibility_testing/compatibility_report.html ./report_dir
'''
sh(script: "sudo bash /xxx/compatibility_testing/report_result.sh", returnStdout:true).trim() // 用于判断云测工具运行后生成的结果是否符合预期
}
}
post {
always {
publishHTML(target: [allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll : true,
reportDir : './report_dir',
reportFiles : 'compatibility_report.html',
reportName : 'compatibility test Report']
)
}
}
}
stage('freshclam') {
agent {
label 'kunpeng_executor'
}
steps{
sh 'freshclam'
}
}
stage('clamscan') {
agent {
label 'kunpeng_executor'
}
steps{
sh 'clamscan -i -r /home -l ~/clamscan.log'
}
}
}
}
}
}
}
}
父主题: 代码示例