gpt4 book ai didi

Jenkins 管道,将分支名称传递给 gradle build

转载 作者:行者123 更新时间:2023-12-03 03:12:26 25 4
gpt4 key购买 nike

多分支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 build?

最佳答案

我觉得可以在命令行直接传SonarQube参数:

stage('Sonarscan') {
withSonarQubeEnv('SONAR') {
bat "gradlew sonarqube -Dsonar.branch.name=${BRANCH_NAME} --info"
}
}

关于Jenkins 管道,将分支名称传递给 gradle build,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51057770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com