Skip to content

Commit

Permalink
#16 Fixes BRANCH_NAME=null for SQ analyses in non-multi-branch pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
schnatterer committed Jul 24, 2018
1 parent 8bbe7fb commit 68e7f52
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/com/cloudogu/ces/cesbuildlib/SonarQube.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class SonarQube implements Serializable {
// Avoid exception "The main branch must not have a target" on master branch
mvn.additionalArgs += " -Dsonar.branch.target=master "
}
} else {
} else if (script.env.BRANCH_NAME) {
mvn.additionalArgs += " -Dsonar.branch=${script.env.BRANCH_NAME} "
}
}
Expand Down
17 changes: 17 additions & 0 deletions test/com/cloudogu/ces/cesbuildlib/SonarQubeTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ class SonarQubeTest {
assert exception.message == "Requires either 'sonarQubeEnv', 'token' or 'usernamePassword' parameter."
}

@Test
void analyzeWithoutBranchName() throws Exception {
def sonarQube = new SonarQube(scriptMock, [usernamePassword: 'usrPwCred', sonarHostUrl: 'http://ces/sonar'])

scriptMock.env = [
USERNAME: 'usr',
PASSWORD: 'pw',
]

sonarQube.analyzeWith(mavenMock)

assert mavenMock.args ==
'sonar:sonar -Dsonar.host.url=http://ces/sonar -Dsonar.login=usr -Dsonar.password=pw '
assert !mavenMock.additionalArgs.contains('-Dsonar.branch')
assert scriptMock.actualUsernamePasswordArgs['credentialsId'] == 'usrPwCred'
}

void analyzeWith(SonarQube sonarQube) throws Exception {
scriptMock.env = [
SONAR_MAVEN_GOAL : 'sonar:sonar',
Expand Down

0 comments on commit 68e7f52

Please sign in to comment.