task sonarqubeResult {
doLast {
def branchName = envOrDefault('BRANCH_NAME', null)
def sonarHost = envOrDefault('SONAR_HOST_URL', null)
def sonarAuthToken = envOrDefault('SONAR_AUTH_TOKEN', null)
if (!branchName || !sonarHost || !sonarAuthToken) {
throw new GradleException('Sonarqube / Pipeline environment variables not set.')
}
def projectKey = project.group + ':' + project.name + ':' + branchName
def url = sonarHost + '/api/qualitygates/project_status?projectKey=' + projectKey
def basicAuth = (sonarAuthToken + ":").bytes.encodeBase64().toString()
def json = url.toURL().getText(requestProperties: [Authorization: 'Basic ' + basicAuth])
def parsed = new groovy.json.JsonSlurper().parseText(json)
println 'Quality Gate Status is: ' + parsed['projectStatus']['status']
}
}
The group is effectively a namespace for identifying the artifact or artifacts produced by a build. (https://stackoverflow.com/a/31440557).
group = 'com.example'
name = 'example'