Jenkins multibranch pipeline pass BRANCH_NAME to gradle build

(Gilbert Rebhan) #1

a multibranch jenkins pipeline calls a gradle build.
Need to pass the BRANCH_NAME to the sonarqube task in build.gradle:

sonarqube {
properties {
property “”, “https://sonar
property “sonar.projectKey”, “”
property “sonar.projectName”, “”
property “sonar.binaries”, “build”
property “”, “${branchname}” <---------------
property “”, “master”

Tried with:

  • direct use of ${BRANCH_NAME} in gradle build
  • gradlew Dbranchname=${BRANCH_NAME} in Jenkinsfile
  • gradlew Pbranchname=${BRANCH_NAME} in Jenkinsfile
  • def branchname=${BRANCH_NAME} before calling gradlew in Jenkinsfile

but nothing worked, the property branchname is always unknown.
How to pass a property from Jenkinsfile to gradle build ?

(Gilbert Rebhan) #2

Solved, works with directly passing the sonarqube property via commandline like that:

stage(‘Sonarscan’) {
withSonarQubeEnv(‘SONAR’) {
bat “gradlew sonarqube${BRANCH_NAME} --info”