-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
132 lines (115 loc) · 4.42 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
#!/usr/bin/env groovy
/*
* Jenkinsfile
* JenkinsPhatblatServices
*
* Updates pbjenkins formula in phatblat/homebrew-services.
*/
import hudson.model.Result
String MAIL_TO = JenkinsLocationConfiguration.get().getAdminAddress()
echo("MAIL_TO: $MAIL_TO")
properties([
buildDiscarder(logRotator(numToKeepStr: '100')),
disableConcurrentBuilds(),
// Don't trigger this job when changes are found from branch indexing.
//overrideIndexTriggers(false),
parameters([
string(
name: 'newVersion',
defaultValue: '2.168',
description: 'New version of Jenkins.'
),
string(
name: 'fileHash',
defaultValue: '83756847b09e754829aaf343d2f11a8c84b097e922d1770dc53b8c8267184e62',
description: 'SHA-256 hash of war file.'
),
]),
])
// Parmaeters
String newVersion = params.newVersion
String fileHash = params.fileHash
// Global variables
String fileName = "Formula/pbjenkins.rb"
String fileContents
try {
timeout(time: 1, unit: 'HOURS') {
withEnv(['LANG=en_US.UTF-8']) {
node {
stage("✔️ Parameters") {
echo("newVersion: $newVersion")
echo("fileHash: $fileHash")
if (newVersion == null || fileHash == null) {
String message = "Required parameters are missing"
echo(message)
currentBuild.rawBuild.@result = Result.FAILURE
throw new Exception(message)
}
}
stage("🛒 Checkout") {
git(url: "[email protected]:phatblat/homebrew-services.git")
}
stage("⚖️ Compare Version") {
// https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#readfile-read-file-from-workspace
String oldContents = readFile(fileName)
echo oldContents
def lines = oldContents.split('\n')
lines.eachWithIndex { line, index ->
if (currentBuild.result && currentBuild.result != 'SUCCESS') {
return
}
echo("line $index: $line")
// Version in url
if (line.startsWith(" url")) {
// Find version
// url "http://mirrors.jenkins.io/war/2.167/jenkins.war"
if (line.contains(newVersion)) {
String message = "Version $newVersion is already in formula."
echo message
currentBuild.rawBuild.@result = Result.ABORTED
return
}
fileContents += " url \"http://mirrors.jenkins.io/war/$newVersion/jenkins.war\"\n"
}
else if (line.startsWith(" sha256")) {
// sha256 "5218a0db16e5815eec7f286006b677d935bc4be7a3ea9fef8aba087041c8a37e"
fileContents += " sha256 \"$filehash\"\n"
}
else {
fileContents += line + '\n'
}
}
}
echo "currentBuild.result: ${currentBuild.result}"
if (currentBuild.result && currentBuild.result != 'SUCCESS') {
return
}
stage("🍼 Update Formula") {
// https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#writefile-write-file-to-workspace
writeFile(file: fileName, text: fileContents)
archiveArtifacts(fileName)
}
}
}
}
}
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
}