forked from jenkinsci/build-monitor-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline.groovy
135 lines (100 loc) · 3.93 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
node('standard') {
git url: '[email protected]:jan-molak/jenkins-build-monitor-plugin.git'
use_jdk '1.6.0_45'
use_nodejs '0.10.26'
with_browser_stack 'linux-x64', {
mvn "release-candidate:updateVersion"
mvn "clean verify"
def version = read_property('version', 'target/classes/build-monitor.properties');
assign_build_name version
push_release_branch_for version
}
archive_artifacts 'target/*.hpi,pom.xml'
archive_junit_results '**/target/surefire-reports/TEST-*.xml,**/target/javascript/test-results.xml'
}
// --
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 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 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
}
}