初识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/)
}
}
stage(‘Sonar’) {
withSonarQubeEnv(‘sonar’){
if (isUnix()) {
sh “’ {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: 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}—”
}
}
}

猜你喜欢

转载自blog.csdn.net/fbb1995/article/details/80224943