【发布时间】:2020-07-28 05:31:35
【问题描述】:
我有一个非常简单的管道。一切都在我的 pom.xml 文件和 .m2/settings.xml 中定义。当 SonarQube 的质量门失败时,我想将我的构建设置为在 Jenkins 上不稳定。这是我所做的,但我有几个错误,比如“预期的}”。有谁知道它是如何工作的? 请注意,环境部分是可选的。 谢谢。
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"
}
}
}
}
}
}
【问题讨论】:
标签: jenkins sonarqube jenkins-pipeline