forked from stanfordnlp/CoreNLP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile_scripted_pipeline
executable file
·54 lines (50 loc) · 1.6 KB
/
Jenkinsfile_scripted_pipeline
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
node {
try {
def gradle_home = tool name: 'gradle:4.10.3', type: 'gradle'
env.PATH = "${gradle_home}/bin:${env.PATH}"
stage('Checkout SCM'){
checkout scm
}
stage('Build') {
sh 'gradle clean'
sh 'gradle build'
}
stage('SonarQube Analysis') {
withSonarQubeEnv('sonarqube') {
sh 'gradle --info sonarqube'
}
}
stage("Quality Gate") {
currentBuild.result = 'SUCCESS'
timeout(time: 20, unit: 'MINUTES') {
def qg = waitForQualityGate()
if (qg.status != 'OK' & qg.status != 'WARN') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
} else if (qg.status == 'WARN') {
currentBuild.result = 'UNSTABLE'
echo "The ${currentBuild.result} state is due to quality gate result: ${qg.status}"
}
}
}
stage('Delivery'){
if(currentBuild.result == 'SUCCESS'){
sh "gradle publish -Pversion=1.0.${env.BUILD_NUMBER} -x javadoc"
}
}
} catch (e) {
currentBuild.result = 'FAILURE'
throw e
} finally {
notifyBuild("${currentBuild.result}")
}
}
def notifyBuild(def buildStatus) {
buildStatus = buildStatus ?: 'FAILURE'
def colorMap = [ 'SUCCESS': 'good', 'UNSTABLE': 'warning', 'FAILURE': 'danger' ]
def resultMap = [ 'SUCCESS': 'Success', 'UNSTABLE': 'Unstable', 'FAILURE': 'Failure' ]
def subject = "${env.JOB_NAME} - #${env.BUILD_NUMBER}"
def result = resultMap[buildStatus]
def summary = "${subject} ${result} after ${currentBuild.durationString.replace(' and counting', '')} (<${env.BUILD_URL}|Details>)"
def colorName = colorMap[buildStatus]
slackSend (color: colorName, message: summary)
}