-
Notifications
You must be signed in to change notification settings - Fork 166
/
node-test-pull-request-lite-pipeline.jenkinsfile
90 lines (83 loc) · 3.02 KB
/
node-test-pull-request-lite-pipeline.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
#!/usr/bin/env groovy
pipeline {
agent { label 'jenkins-workspace' }
parameters {
booleanParam(name: 'CERTIFY_SAFE', defaultValue: false, description: 'I have reviewed *the latest version of* these changes and I am sure that they don’t contain any code that could compromise the security of the CI infrastructure.')
string(name: 'PR_ID', defaultValue: '', description: 'PR ID')
}
stages {
stage("Setup repository") {
steps {
checkout(
changelog: false,
poll: false,
scm: [
$class: 'GitSCM',
branches: [[
name: 'refs/heads/_jenkins_local_branch'
]],
userRemoteConfigs: [[
credentialsId: "96d5f81c-e9ad-45f7-ba5d-bc8107c0ae2c",
url: "[email protected]:nodejs/node.git"
]]
]
)
}
}
stage('Preflight') {
steps {
script {
if (!params.CERTIFY_SAFE) {
error "Please certify that you have reviewed the changes to be tested, by ticking the CERTIFY_SAFE checkbox on the job launch page."
}
setupEnv(env, params)
}
}
}
stage('Run tests') {
steps {
script {
def buildParams = setupSubParams(env, params)
def testResult
parallel(
regressionTests: {
testResult = build job: "node-test-commit-linuxone", parameters: buildParams, propagate: false
},
linter: {
build job: "node-linter", parameters: buildParams, propagate: true
}
)
currentBuild.result = testResult.result
}
}
}
}
}
def getBranchName(params) {
if (params.PR_ID) {
return "refs/pull/${params.PR_ID}/head"
} else {
return "refs/heads/main"
}
}
def setupEnv(env, params) {
def node_version = sh(script: "python tools/getnodeversion.py", returnStdout: true).trim()
echo "Detected node version: ${node_version}"
def node_version_parts = node_version.tokenize('.')
env.NODE_MAJOR_VERSION = node_version_parts[0]
echo "NODE_MAJOR_VERSION=${env.NODE_MAJOR_VERSION}"
}
def setupSubParams(env, params) {
def pr = [:] // Mutable copy of params.
params.each{ key, value -> pr.put(key, value) }
pr["GITHUB_ORG"] = "nodejs"
pr["REPO_NAME"] = "node"
pr["GIT_REMOTE_REF"] = getBranchName(params)
pr["GIT_ORIGIN_SCHEME"] = "[email protected]:"
pr['NODE_MAJOR_VERSION'] = env.NODE_MAJOR_VERSION
p = []
for (param in pr) {
p.push(string(name: param.key, value: "${param.value}"))
}
return p
}