初识jenkins pipeline

使用jenkins pipeline插件构建一个job,主要是:从gitlab拉取代码–编译–sonar分析–quality gate判断是否通过质量阀
脚本如下:
node {
def mvnHome
stage(‘Preparation’) { // for display purposes
// Get some code from a GitHub repository
git branch: ”, credentialsId: ”, url: ”
// Get the Maven tool.
// ** NOTE: This ‘M3’ Maven tool must be configured
// ** in the global configuration.
mvnHome = tool ‘maven’
}
stage(‘Build’) {
// Run the maven build
if (isUnix()) {
sh “’{mvnHome}/bin/mvn’ clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=true”  
      } else {  
         bat(/”
{mvnHome}/bin/mvn’ clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=true”        } else {           bat(/”
{mvnHome}\bin\mvn” clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=true/)
}
}
stage(‘Sonar’) {
withSonarQubeEnv(‘sonar’){
if (isUnix()) {
sh “’{mvnHome}/bin/mvn’ sonar:sonar”  
      } else {  
         bat(/”
{mvnHome}/bin/mvn’ sonar:sonar”        } else {           bat(/”
{mvnHome}\bin\mvn” sonar:sonar/)
}}
}
sleep(10)
stage(‘Quality Gate’) {
timeout(3) {
def qg = waitForQualityGate()
echo “—before qg: qg.statusif(qg.status!=OK)errorSonarqubefailure:$qg.statusechoafterqg: q g . s t a t u s — ” i f ( q g . s t a t u s ! = ‘ O K ′ ) e r r o r “ 未 通 过 S o n a r q u b e 的 代 码 质 量 阈 检 查 , 请 及 时 修 改 ! f a i l u r e : $ q g . s t a t u s ” e c h o “ — a f t e r q g : {qg.status}—”
}
}
}

你可能感兴趣的:(持续集成,代码检查,jenkins,pipeline,sonar,quality,gate)