multibranch jenkins管道调用gradle构建。
需要将BRANCH_NAME
传递给build.gradle中的sonarqube任务:
sonarqube {
properties {
property "sonar.host.url", "https://sonar"
property "sonar.projectKey", "com.foo.bar:Foobar"
property "sonar.projectName", "com.foo.bar-Foobar"
property "sonar.binaries", "build"
property "sonar.branch.name", "${branchname}" <---------------
property "sonar.branch.target", "master"
}
}
我试过了:
stage('Sonarscan') {
withSonarQubeEnv('SONAR') {
bat "gradlew -Pbranchname=${BRANCH_NAME} sonarqube --info"
}
}
输出:
* What went wrong:
A problem occurred evaluating root project 'fooBar'.
> Cannot get property 'branchname' on extra properties extension as it does not exist
和
stage('Sonarscan') {
withSonarQubeEnv('SONAR') {
bat "gradlew -Dbranchname=${BRANCH_NAME} sonarqube --info"
}
}
输出:
* What went wrong:
A problem occurred evaluating root project 'fooBar'.
> Could not get unknown property 'branchname' for root project 'sfrToolbarContract' of type org.gradle.api.Project.
并且:
stage('Sonarscan') {
withSonarQubeEnv('SONAR') {
def branchname = "${BRANCH_NAME}"
bat "gradlew sonarqube --info"
}
}
但管道工作刚刚挂起。 如何将属性从Jenkinsfile传递给gradle构建?
我想你可以直接在命令行上传递SonarQube参数:
stage('Sonarscan') {
withSonarQubeEnv('SONAR') {
bat "gradlew sonarqube -Dsonar.branch.name=${BRANCH_NAME} --info"
}
}