Jenkins管道,将branchname传递给gradle构建

时间:2018-06-27 08:12:09

标签: jenkins gradle groovy sonarqube jenkins-pipeline

多分支詹金斯管道调用gradle build。
需要将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" } } 传递给build.gradle中的sonarqube任务:

  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"
    }
  }

还有:

$mail->AddEmbeddedImage('generate.php?text='.$fulldetail , 'qr');

但是管道作业只是挂起。
如何将属性从Jenkinsfile传递到gradle构建?

1 个答案:

答案 0 :(得分:2)

我认为您可以在命令行上直接传递SonarQube参数:

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