-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathJenkinsfile
139 lines (124 loc) · 4.27 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
pipeline {
parameters { booleanParam(name: 'create_release', defaultValue: false,
description: 'If true, create a release artifact and publish to ' +
'the artifactory release PyPi or public PyPi.') }
options {
timeout(time: 1, unit: 'HOURS')
}
agent {
node {
label "python-gradle"
}
}
environment {
PATH = "/home/jenkins/.local/bin:$PATH"
REQUESTS_CA_BUNDLE = "/etc/ssl/certs"
}
stages {
stage ("create virtualenv") {
steps {
this.notifyBB("INPROGRESS")
sh "./gradlew -i cleanAll installCIDependencies"
}
}
stage ("bump version pre-build") {
when {
expression { return params.create_release }
}
steps {
// This will drop the dev suffix if we are releasing
// X.Y.Z.devN -> X.Y.Z
sh "./gradlew -i bumpVersionRelease"
}
}
stage ("test/build distribution") {
steps {
sh "./gradlew -i build"
}
}
stage ("report on tests") {
steps {
junit "build/test_report.xml"
cobertura autoUpdateHealth: false,
autoUpdateStability: false,
coberturaReportFile: 'build/coverage.xml',
failUnhealthy: false,
failUnstable: false,
maxNumberOfBuilds: 0,
onlyStable: false,
sourceEncoding: 'ASCII',
zoomCoverageChart: false
}
}
stage ("publish release") {
when {
branch 'master'
expression { return params.create_release }
}
steps {
sh "./gradlew -i publishRelease"
sh "./gradlew -i gitTagCommitPush"
sh "./gradlew -i bumpVersionPostRelease gitCommitPush"
}
}
stage ("publish snapshot") {
when {
branch 'master'
not { expression { return params.create_release } }
}
steps {
sh "./gradlew -i publishSnapshot"
script {
def ignoreAuthors = ["jenkins", "Jenkins User", "Jenkins Builder"]
if (!ignoreAuthors.contains(gitAuthor())) {
sh "./gradlew -i bumpVersionDev gitCommitPush"
}
}
}
}
}
post {
always {
notifyBuildOnSlack(currentBuild.result, currentBuild.previousBuild?.result)
this.notifyBB(currentBuild.result)
}
cleanup {
deleteDir()
}
}
}
def notifyBB(String state) {
// on success, result is null
state = state ?: "SUCCESS"
if (state == "SUCCESS" || state == "FAILURE") {
currentBuild.result = state
}
notifyBitbucket commitSha1: "${GIT_COMMIT}",
credentialsId: 'aea50792-dda8-40e4-a683-79e8c83e72a6',
disableInprogressNotification: false,
considerUnstableAsSuccess: true,
ignoreUnverifiedSSLPeer: false,
includeBuildNumberInKey: false,
prependParentProjectKey: false,
projectKey: 'SW',
stashServerBaseUrl: 'https://aicsbitbucket.corp.alleninstitute.org'
}
def notifyBuildOnSlack(String buildStatus = 'STARTED', String priorStatus) {
// build status of null means successful
buildStatus = buildStatus ?: 'SUCCESS'
// Override default values based on build status
if (buildStatus != 'SUCCESS') {
slackSend (
color: '#FF0000',
message: "${buildStatus}: '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})"
)
} else if (priorStatus != 'SUCCESS') {
slackSend (
color: '#00FF00',
message: "BACK_TO_NORMAL: '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})"
)
}
}
def gitAuthor() {
sh(returnStdout: true, script: 'git log -1 --format=%an').trim()
}