-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
163 lines (146 loc) Β· 5.67 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env groovy
/*
* Jenkinsfile
* JenkinsHomebrew
*
* Checks for new versions of Jenkins, updating the core formula when found.
*/
import jenkins.model.*
import hudson.model.Result
def MAIL_TO = JenkinsLocationConfiguration.get().getAdminAddress()
echo "MAIL_TO: $MAIL_TO"
properties([
// Don't trigger this job when changes are found from branch indexing.
//overrideIndexTriggers(false),
disableConcurrentBuilds(),
pipelineTriggers([
cron('H 1 * * *')
]),
buildDiscarder(logRotator(numToKeepStr: '100')),
])
// Global variables
String currentVersion
String newVersion
String file
String url
String hash
try {
timeout(time: 1, unit: 'HOURS') {
withEnv(['LANG=en_US.UTF-8']) {
node {
stage("ππ»ββοΈ Current Version") {
// Parse version from homebrew formula json
// https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#sh-shell-script
currentVersion = sh(
script: """
brew info --json=v1 jenkins \
| jq .[0].versions.stable \
| tr -d '"'
""",
label: "β¨ Version",
returnStdout: true
).trim()
echo "Current Jenkins formula version: $currentVersion"
}
stage("π‘ New Release") {
// Increment minor version
def (major, minorString) = currentVersion.tokenize('.')
Integer minor = minorString as Integer
minor++
newVersion = "$major.$minor"
echo "Checking for new Jenkins release with version: $newVersion"
file = "jenkins-${newVersion}.war"
url = "http://mirrors.jenkins.io/war/$newVersion/jenkins.war"
Integer status = sh(
script: """
curl \
--head \
--fail \
--silent \
$url
""",
label: "βοΈ Check",
returnStatus: true
)
if (status != 0) {
echo "Version $currentVersion is still the latest. π"
currentBuild.rawBuild.@result = hudson.model.Result.ABORTED
} else {
echo "Jenkins $newVersion IS NOW AVAILABLE! π"
}
}
echo "currentBuild.result: ${currentBuild.result}"
// build.@result = hudson.model.Result.SUCCESS
// build.@result = hudson.model.Result.NOT_BUILT
// build.@result = hudson.model.Result.UNSTABLE
// build.@result = hudson.model.Result.FAILURE
// build.@result = hudson.model.Result.ABORTED
if (currentBuild.result && currentBuild.result != 'SUCCESS') {
return
}
stage("ππ» Download") {
echo "ππ» Downloading Jenkins $newVersion - $url"
sh(
script: """
curl \
--fail \
--location \
--silent \
--output $file \
$url
""",
label: "ππ» Download"
)
hash = sh(
script: """
shasum \
--algorithm 256 \
$file \
| cut -d' ' -f1
""",
label: "π’ Hash",
returnStdout: true
).trim()
echo "File hash: $hash"
}
stage("βοΈ Notify") {
mail to: MAIL_TO,
subject: "β¨π·π»ββοΈ Jenkins $newVersion has been released",
body: """
Jenkins $newVersion
$url
$hash
"""
}
} // node
// Intentionally run outside of a node block because: It is a waste of an executor slot to wrap the build
// step in node. Your upstream executor will just be sitting idle for no reason.
stage("πΌ Formula") {
// https://jenkins.io/doc/pipeline/steps/pipeline-build-step/#build-build-a-job
build job: "../JenkinsPhatblatServices/master",
parameters: [
string(name: "newVersion", value: newVersion),
string(name: "fileHash", value: hash)
]
}
}
}
}
catch (Exception ex) {
String jobName = env.JOB_NAME
String buildNumber = env.BUILD_NUMBER
String subject = "π·π»ββοΈ [FAILURE] $jobName - Build #$buildNumber"
String body = """$jobName
|Build #${buildNumber} - FAILURE
|
|${env.BUILD_URL}
|
|${ex}
|
|${env.BUILD_URL}console
|""".stripMargin()
mail to: MAIL_TO,
subject: subject,
body: body
throw ex
}