如果声纳质量门失败,则设置构建不稳定



我有一个非常简单的管道。所有东西都在我的pom.xml文件和.m2/settings.xml中定义。当SonarQube的质量门失败时,我想在Jenkins上将我的构建设置为不稳定。以下是我所做的,但我有几个错误,比如"expected}"。有人知道它是怎么工作的吗?请注意,环境部分是可选的。非常感谢。

pipeline {
agent {
label "master"
}
tools {
// Note: this should match with the tool name configured in your jenkins instance (JENKINS_URL/configureTools/)
maven "Maven 3.6.0"
jdk 'Java 1.8'
}
environment {
// This can be nexus3 or nexus2
NEXUS_VERSION = "nexus3"
// This can be http or https
NEXUS_PROTOCOL = "http"
// Where your Nexus is running
NEXUS_URL = "192.168.1.8:8081"
// Repository where we will upload the artifact
NEXUS_REPOSITORY = "repository-example"
// Jenkins credential id to authenticate to Nexus OSS
NEXUS_CREDENTIAL_ID = "nexus-credentials"
}
stages {
stage ('Initialize') {
steps {
sh '''
echo "PATH = ${PATH}"
echo "M2_HOME = ${M2_HOME}"
'''
}
}
stage("mvn clean deploy") {
steps {
script {
// If you are using Windows then you should use "bat" step
// Since unit testing is out of the scope we skip them
sh "mvn -B clean deploy"
}
}
}
stage ("SonarQube check") {
steps {
script {
sh 'mvn -B sonar:sonar'
}
step {                     
qualitygate = waitForQualityGate()                     
if (qualitygate.status != "OK") {                         
currentBuild.result = "UNSTABLE"                     
}                 
}  
}
}          
}         
}

您需要将qualitygate的内容和所有内容包装在script块中,如下所示:

stage ("SonarQube check") {
steps {
script {
sh 'mvn -B sonar:sonar'
qualitygate = waitForQualityGate()                     
if (qualitygate.status != "OK") {                         
currentBuild.result = "UNSTABLE"                     
}                 
}
}
}

相关内容

  • 没有找到相关文章

最新更新