-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
77 lines (64 loc) · 2.24 KB
/
Jenkinsfile
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!groovy
node {
stage('Build') {
echo "Running ${env.BUILD_ID} [branch:${env.BRANCH_NAME}] on ${env.JENKINS_URL}"
deleteDir() //delete the cloned dir before each build
checkout scm //Jenkins with multibranch support
sh './gradlew clean build'
stash includes: 'build/libs/*.jar', name: 'app-jar'
}
stage('Code Quality') {
parallel publish_test_reports: {
junit '**/build/test-results/test/*.xml' //publish test reports
},
sonar: {
sh "./gradlew sonarqube"
//qualityGate()
},
owasp_dependency_check: {
sh './gradlew dependencyCheck --info'
}
}
stage('Release') {
sh './gradlew release -Prelease.useAutomaticVersion=true'
sh './gradlew upload'
}
}
/**
* Call Sonar endpoints to extract/evaluate quality gate analysis result
* @return
*/
def qualityGate() {
def props = readProperties file: "build/sonar/report-task.txt"
echo "Quality Gate Properties=${props}"
def sonarServerUrl = props['serverUrl']
def ceTaskUrl = props['ceTaskUrl']
timeout(time: 3, unit: 'MINUTES') {
waitUntil {
ceTask = new URL(ceTaskUrl)
def analysisStatus = getUrlJsonProperty(ceTaskUrl, "status")
echo "Quality Gate analysisStatus: ${analysisStatus}"
return "SUCCESS".equals(analysisStatus)
}
}
def analysisId = getUrlJsonProperty(ceTaskUrl, "analysisId")
echo "Quality Gate analysisId=${analysisId}"
def qualigateUrl = sonarServerUrl + "/api/qualitygates/project_status?analysisId=" + analysisId
def qualitygateStatus = getUrlJsonProperty(qualigateUrl, "status")
echo "Quality Gate status=${qualitygateStatus}"
if ("ERROR".equals(qualitygateStatus)) {
// error "Sonar Quality Gate failure: ${qualitygateStatus}"
currentBuild.result = 'UNSTABLE'
}
}
/**
* Make a request to url and extract a property value from json response
* @param url
* @param property
* @return
*/
def getUrlJsonProperty(url, property) {
sh(script: """
curl -s -k ${url} | sed 's/{.*${property}":"*\\([0-9a-zA-Z]*\\)"*,*.*}/\\1/'
""", returnStdout: true)
}