jenkins+sonarqube流水线脚本模板

pipeline {
//这个任务在哪个主机上运行
//agent any

//将这个项目运行在slave上
agent { label 'node1' }

//参数化构建,主要设定git_version变量的值
parameters {
string(name: 'git_version', defaultValue: 'v1.1', description: '选择你要部署的tag??')
}

stages { //整个部署的任务

stage ('获取代码'){
steps {
checkout([$class: 'GitSCM', branches: [[name: '${git_version}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '7125a93c-b778-496c-a9c2-c0b4b43bfe5e', url: 'git@gitlab.oldxu.com:dev/monitor.git']]])
}
}
stage ('代码质检'){
steps {
withSonarQubeEnv('SonarQube') {
sh '/usr/local/sonar-scanner/bin/sonar-scanner -Dsonar.projectKey=${JOB_NAME} -Dsonar.sources=.'
}
}
}
stage ('代码构建') {
steps {
echo "构建成功"
//sh 'mvn package -Dmaven.test.skip=true' //java项目
}
}
stage ('确认部署?') {
steps {
input message: '是否部署', ok: 'ok'
}
}
stage('代码部署'){
steps {
sh 'sh -x /scripts/html_deploy_tag.sh'
}
}
}

post { //stages所有任务执行后触发post
failure { //构建失败通知
dingTalk accessToken:'daf7d4843cc7d6a9612bf7a76fdc067b38e3927bba1788d2581713a4604d3169',imageUrl: '', jenkinsUrl: 'http://jenkins.oldbgx.com:8080/', message: '代码部署失败', notifyPeople: 'phone'
}

success { //构建成功通知
dingTalk accessToken:'daf7d4843cc7d6a9612bf7a76fdc067b38e3927bba1788d2581713a4604d3169',imageUrl: '', jenkinsUrl: 'http://jenkins.oldbgx.com:8080/', message: '代码部署成功', notifyPeople: 'phone'
}
}
}

 

 

 

 

 

 

 

 

 

自用!!!!!

上一篇:C#-在Sonar中获得代码覆盖率,但没有测试结果(.Net)


下一篇:git jenkins SonarQube手动代码质检