forked from jenkinsci/build-monitor-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline.groovy
172 lines (125 loc) · 5.01 KB
/
pipeline.groovy
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
164
165
166
167
168
169
170
171
172
def version = 'unknown'
stage 'Build'
node('hi-speed') {
git url: '[email protected]:jan-molak/jenkins-build-monitor-plugin.git', branch: 'master'
use_jdk '1.7.latest'
use_nodejs '0.10.26'
mvn "release-candidate:updateVersion"
mvn "clean package --projects build-monitor-plugin"
version = read_property('version', 'build-monitor-plugin/target/classes/build-monitor.properties');
assign_build_name version
archive_junit_results 'build-monitor-plugin/target/surefire-reports/TEST-*.xml,build-monitor-plugin/target/javascript/test-results.xml'
stash name: 'sources', includes: '**,build-monitor-plugin/target/*.hpi', excludes: 'build-monitor-plugin/target/*,**/node_modules/*'
}
stage 'Verify'
node('hi-speed') {
unstash 'sources'
use_jdk '1.7.latest'
with_browser_stack 'linux-x64', {
mvn "clean verify --projects build-monitor-acceptance"
}
archive_artifacts 'build-monitor-plugin/target/*.hpi,pom.xml,build-monitor-plugin/pom.xml,build-monitor-acceptance/pom.xml,build-monitor-acceptance/target/failsafe-reports/*-output.txt'
archive_junit_results 'build-monitor-acceptance/target/failsafe-reports/TEST-*.xml'
archive_html 'Serenity', 'build-monitor-acceptance/target/site/serenity'
}
stage 'Publish to GitHub'
node('hi-speed') {
unstash 'sources'
create_and_push_release_branch_for version
}
// --
def assign_build_name (new_name) {
currentBuild.setDisplayName(new_name)
}
def read_property(property_name, properties_file) {
def matcher = readFile(properties_file) =~ "${property_name}=(.+)"
if (! matcher) {
throw "Couldn't find '${property_name}' in '${properties_file}" as Throwable
}
return matcher[0][1]
}
def archive_artifacts(artifacts) {
step([$class: 'ArtifactArchiver', artifacts: artifacts])
}
def archive_junit_results(results) {
step([$class: 'JUnitResultArchiver', testResults: results])
}
def archive_html(report_name, path) {
publishHTML(target: [
reportName : report_name,
reportDir: path,
reportFiles: 'index.html',
keepAll: true,
alwaysLinkToLastBuild: true,
allowMissing: false
])
}
def with_browser_stack(version, actions) {
echo "> Using BrowserStackLocal for '${version}'"
if (! env.BROWSERSTACK_AUTOMATION_KEY) {
throw "Looks like you haven't specified the BROWSERSTACK_AUTOMATION_KEY env variable." as Throwable
}
def auth_key = env.BROWSERSTACK_AUTOMATION_KEY
if (!fileExists("/var/tmp/BrowserStackLocal")) {
exec "curl -sS https://www.browserstack.com/browserstack-local/BrowserStackLocal-${version}.zip > /var/tmp/BrowserStackLocal.zip", 'Downloading BrowserStackLocal'
exec "unzip -o /var/tmp/BrowserStackLocal.zip -d /var/tmp", 'Unpacking BrowserStackLocal'
exec "chmod +x /var/tmp/BrowserStackLocal", 'Making the BrowserStackLocal binary executable'
}
spawn "browserstack-${version}", "/var/tmp/BrowserStackLocal ${auth_key} -onlyAutomate -forcelocal"
try {
actions()
} catch(e) {
echo "ERROR: ${e}"
throw e
} finally {
stop "browserstack-${version}"
}
}
def spawn (name, executable) {
exec "BUILD_ID=dontKillMe nohup ${executable} > /var/tmp/${name}.log 2>&1 & echo \$! > /var/tmp/${name}.pid", "Spawning ${name}"
def pid = exec "cat /var/tmp/${name}.pid"
echo "> Started ${name} with Process ID: ${pid}"
}
def stop (name) {
def pid = exec "cat /var/tmp/${name}.pid"
exec "kill ${pid}", "Stopping ${name} [${pid}]"
exec "rm /var/tmp/${name}.pid", "Removing the PID file for ${name}"
}
def use_jdk (version) {
echo "> Using JDK ${version}"
env.JAVA_HOME="/opt/jdk/jdk${version}"
env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"
}
def use_nodejs (version) {
exec 'wget --quiet https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/node/use-node -O use-node', 'Downloading Node.js installer'
exec "NODE_VERSION=${version} . ./use-node", "Installing Node.js ${version}"
def node_home = exec 'dirname `which node`'
env.PATH="${node_home}:${env.PATH}"
echo "> Using node.js at: ${node_home}"
}
def mvn (command) {
def maven_version = '3.2.5'
env.M2_HOME = "/opt/maven/apache-maven-${maven_version}"
def mvn_home = tool "Maven (${maven_version})"
// `sh` instead of `exec` as we actually do care about the output
sh "${mvn_home}/bin/mvn -B -e -q ${command}"
}
def create_and_push_release_branch_for(version) {
sh "git checkout -b release-${version}"
sh "git commit -a -m \"Release candidate v${version}\""
sh "git push origin release-${version}"
}
def exec (command, description='') {
if (description) {
echo "> '${description}'"
} else {
echo "> '${command}'"
}
try {
sh "#!/usr/bin/env bash\n ${command} | tail -n 1 > /tmp/pipeline"
return readFile('/tmp/pipeline').split("\r?\n")[0]
} catch(e) {
echo "Executing '${description}': ${command} failed: ${e}"
throw e
}
}