Skip to content

Commit 537098c

Browse files
[green-dragon-migration] Rewrite relay (#159)
## In This PR Rewrite relay.groovy, namely the following changes were made: * Take in a list of jobs rather than a pattern. We do this so that we don't have to rely on `Jenkins.getInstance()`, `job.getName()`, or `jenkins.getAllItems()` which are insecure Jenkins methods and will result in security vulnerabilities if we approve them. * Pull artifacts from S3 storage * Implement a fix for LNT server overloading until we figure out issues with the server This code has been tested on https://green.lab.llvm.org/
1 parent c3918ea commit 537098c

File tree

1 file changed

+40
-41
lines changed

1 file changed

+40
-41
lines changed

zorg/jenkins/relay.groovy

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,31 @@
11
#!/usr/bin/env groovy
2-
@NonCPS
3-
private def get_matching_jobs(pattern) {
4-
def jobs = []
5-
for (job in Jenkins.getInstance().getAllItems(Job)) {
6-
def jobname = job.getName()
7-
def m = jobname =~ pattern
8-
if (m) {
9-
def shortname = m[0][1]
10-
jobs.push([shortname, jobname])
11-
}
12-
}
13-
return jobs
14-
}
15-
162
private def basename(path) {
173
return path.drop(path.lastIndexOf('/') + 1)
184
}
195

20-
private def relay_steps(job_pattern, artifact_url, last_good_properties_url) {
6+
private def relay_steps(joblist, artifact_url, last_good_properties_url) {
217
// The upstream jobs triggering the relay produce a
228
// "last_good_build.properties" file that contains a reference to the
239
// compiler artifact that should be used for this run and which llvm
2410
// revision it is based on.
25-
propfile = basename(last_good_properties_url)
26-
sh """
27-
rm -f ${propfile}
28-
curl -fksSO "${last_good_properties_url}"
29-
"""
11+
// Ensure you have the AWS CLI on path before triggering the relay
12+
withCredentials([string(credentialsId: 's3_resource_bucket', variable: 'S3_BUCKET')]) {
13+
propfile = basename(last_good_properties_url)
14+
sh """
15+
rm -f ${propfile}
16+
aws s3 cp $S3_BUCKET/clangci/${last_good_properties_url} ${propfile}
17+
"""
18+
}
19+
3020
def props = readProperties file: propfile
31-
def artifact = "http://green-dragon-21.local/artifacts/${props.ARTIFACT}"
21+
def artifact = props.ARTIFACT
3222
currentBuild.setDisplayName("${props.GIT_DISTANCE}-${props.GIT_SHA}")
3323

34-
// Trigger all jobs with names matching the `job_pattern` regex.
35-
def joblist = get_matching_jobs(job_pattern)
24+
// Trigger all jobs within the provided list
3625
def parallel_builds = [:]
3726
for (j in joblist) {
38-
def shortname = j[0]
39-
def jobname = j[1]
40-
parallel_builds[shortname] = {
27+
def jobname = j
28+
parallel_builds[jobname] = {
4129
def job_params = [
4230
[$class: 'StringParameterValue',
4331
name: 'ARTIFACT',
@@ -49,28 +37,39 @@ curl -fksSO "${last_good_properties_url}"
4937
name: 'GIT_DISTANCE',
5038
value: props.GIT_DISTANCE],
5139
]
52-
build job: jobname, parameters: job_params
40+
build job: jobname, parameters: job_params, propagate: false
5341
}
5442
}
55-
parallel parallel_builds
56-
}
5743

58-
def pipeline(job_pattern,
59-
artifact_url='http://green-dragon-21.local/artifacts/',
60-
last_good_properties_url='http://green-dragon-21.local/artifacts/clang-stage1-RA/last_good_build.properties') {
61-
node('master') {
62-
stage('main') {
63-
relay_steps job_pattern, artifact_url, last_good_properties_url
64-
}
44+
// Workaround to prevent LNT jobs from running in parallel and overloading the LNT server with submissions
45+
if(joblist.any { it.contains("lnt-ctmark") }) {
46+
for (j in joblist) {
47+
parallel_builds[j].call()
48+
}
49+
} else {
50+
parallel parallel_builds
6551
}
6652
}
6753

68-
def lldb_pipeline(job_pattern,
69-
artifact_url='http://green-dragon-21.local/artifacts/',
70-
last_good_properties_url='http://green-dragon-21.local/artifacts/lldb-cmake/last_good_build.properties') {
71-
node('master') {
54+
def pipeline(joblist,
55+
artifact_url='llvm.org/clang-stage1-RA/latest',
56+
last_good_properties_url='llvm.org/clang-stage1-RA/last_good_build.properties') {
57+
node(label: 'macos-x86_64') {
7258
stage('main') {
73-
relay_steps job_pattern, artifact_url, last_good_properties_url
59+
// Download aws CLI used to gather artifacts
60+
sh """
61+
rm -rf venv
62+
python3 -m venv venv
63+
set +u
64+
source ./venv/bin/activate
65+
pip install awscli
66+
set -u
67+
"""
68+
withEnv([
69+
"PATH=$PATH:$WORKSPACE/venv/bin:/usr/bin:/usr/local/bin"
70+
]) {
71+
relay_steps joblist, artifact_url, last_good_properties_url
72+
}
7473
}
7574
}
7675
}

0 commit comments

Comments
 (0)