forked from spotbugs/spotbugs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsonar.gradle
50 lines (43 loc) · 1.92 KB
/
sonar.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
apply plugin: 'org.sonarqube'
def isTarget = 'master'.equals(System.env.TRAVIS_BRANCH) || 'release-3.1'.equals(System.env.TRAVIS_BRANCH)
// for security reasons travis secure variables are defined when build is
// initiated by a pull request from same repository only
// so pull requests from external repositories can not be analysed by sonar
def isSecure = 'true'.equals(System.env.TRAVIS_SECURE_ENV_VARS)
if (!isSecure || !isTarget) {
rootProject.tasks['sonarqube'].setEnabled(false)
return
}
def isPush = 'push'.equals(System.env.TRAVIS_EVENT_TYPE);
def isPullRequest = 'pull_request'.equals(System.env.TRAVIS_EVENT_TYPE);
rootProject.tasks['sonarqube'].setEnabled(isPush || isPullRequest)
sonarqube {
properties {
property 'sonar.host.url', System.env.SONAR_HOST_URL
property 'sonar.login', System.env.SONAR_LOGIN
property 'sonar.projectKey', 'com.github.spotbugs.spotbugs'
property 'sonar.projectName', 'SpotBugs'
property 'sonar.projectVersion', rootProject.version
property 'sonar.organization', 'spotbugs'
}
}
if (isPullRequest) {
sonarqube {
properties {
// https://docs.sonarqube.org/7.6/analysis/pull-request/
// https://github.com/travis-ci/travis-build/blob/6af6dd723bd6b364dc29ad74af7f22438a16494d/lib/travis/build/addons/sonarcloud.rb#L123-L127
property 'sonar.pullrequest.key', System.env.TRAVIS_PULL_REQUEST
property 'sonar.pullrequest.branch', System.env.TRAVIS_PULL_REQUEST_SLUG
property 'sonar.pullrequest.base', System.env.TRAVIS_BRANCH
property 'sonar.pullrequest.provider', 'GitHub'
property 'sonar.pullrequest.github.repository', System.env.TRAVIS_REPO_SLUG
}
}
} else {
sonarqube {
properties {
// https://docs.sonarqube.org/display/PLUG/Branch+Plugin
property 'sonar.branch.name', System.env.TRAVIS_BRANCH
}
}
}