Skip to content

Commit c89db0e

Browse files
committed
Fix: pipeline triggers
Signed-off-by: Chris Yan <chrisyan@microsoft.com>
1 parent 77d10ca commit c89db0e

4 files changed

Lines changed: 102 additions & 23 deletions

File tree

.jenkins/Jenkinsfile

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ List<String> APPROVED_AUTHORS = [
5858
'yentsanglee'
5959
]
6060

61-
/* Check if BRANCH is specified by multibranch pipeline job
62-
env.BRANCH_NAME is only set when a build is triggered by a multibranch pipeline job.
63-
*/
64-
GLOBAL_BRANCH_NAME = env.BRANCH_NAME ?: params.BRANCH
65-
6661
pipeline {
6762
agent any
6863
options {
@@ -71,8 +66,8 @@ pipeline {
7166
}
7267
parameters {
7368
string(name: 'PULL_REQUEST_ID', defaultValue: '', description: '[Optional] If testing a PR - enter PR #', trim: true)
74-
string(name: 'REPOSITORY_NAME', defaultValue: 'cyandevs/openenclave', description: 'GitHub repository to checkout', trim: true)
75-
string(name: 'BRANCH', defaultValue: 'master', description: '[Optional] The branch used to checkout the repository', trim: true)
69+
string(name: 'REPOSITORY_NAME', defaultValue: 'openenclave/openenclave', description: '[Optional] If testing a branch - enter GitHub repository to checkout', trim: true)
70+
string(name: 'BRANCH', defaultValue: 'master', description: '[Optional] If testing a branch - enter branch to checkout', trim: true)
7671
booleanParam(name: 'FULL_TEST_SUITE', defaultValue: false, description: 'Run all tests')
7772
booleanParam(name: 'FORCE_TEST', defaultValue: false, description: 'Force tests to continue even if there are no changes compared to master')
7873
string(name: 'DOCKER_TAG', defaultValue: 'latest', description: 'Version of Docker image "oetools" to use', trim: true)
@@ -103,17 +98,14 @@ pipeline {
10398
script: "curl --silent https://api.github.com/repos/cyandevs/openenclave/pulls/${env.CHANGE_ID} | jq --raw-output '.user | .login'",
10499
returnStdout: true
105100
).trim()
106-
if ( PR_AUTHOR == 'null' ) {
101+
if ( PR_AUTHOR == 'null' || PR_AUTHOR == '' || PR_AUTHOR == null ) {
107102
error("No pull request author found. This is an unexpected error. Does the pull request ID exist?")
108-
}
109-
if ( ! APPROVED_AUTHORS.contains(PR_AUTHOR) ) {
103+
} else if ( APPROVED_AUTHORS.contains(PR_AUTHOR) ) {
104+
println("Pull request author ${PR_AUTHOR} is authorized. Build will continue.")
105+
} else {
110106
currentBuild.result = 'ABORTED'
111107
error("Pull request author ${PR_AUTHOR} is not in the list of authorized users. Aborting build.")
112-
} else {
113-
println("Pull request author ${PR_AUTHOR} is authorized. Build will continue.")
114108
}
115-
// Set pull request ID for standalone builds
116-
PULL_REQUEST_ID = CHANGE_ID
117109
}
118110
}
119111
}
@@ -124,6 +116,7 @@ pipeline {
124116
*/
125117
steps {
126118
script {
119+
boolean continue_build = false
127120
dir("${WORKSPACE}") {
128121
if ( params.PULL_REQUEST_ID ) {
129122
// This is the git ref for a manual PR build
@@ -142,33 +135,71 @@ pipeline {
142135
| grep --invert-match --extended-regexp \'${IGNORED_DIRS_REGEX}\' --no-messages || test \$? = 1
143136
"""
144137
)
145-
if ( CHANGED_FILES == '' ) {
146-
println("No significant changes detected. Testing is not necessary.")
147-
continue_build = false
148-
} else {
138+
if ( CHANGED_FILES != '' ) {
149139
println("Detected the follow file changes: " + CHANGED_FILES)
150140
continue_build = true
141+
} else {
142+
println("No changes detected. Skipping main testing stage.")
151143
}
152144
}
153145
}
154146
}
155147
}
156148
stage('Load library') {
157149
when {
158-
expression {
159-
return continue_build
160-
}
150+
expression { return continue_build }
161151
}
162152
steps {
163153
script {
164154
library "OpenEnclaveJenkinsLibrary@${params.OECI_LIB_VERSION}"
165155
}
166156
}
167157
}
158+
stage('Set PULL_REQUEST_ID') {
159+
/* This stage sets PULL_REQUEST_ID so that the downstream pipelines can use it.
160+
* The variable is necessary when a build is:
161+
* triggered by a multibranch pipeline job
162+
* OR is manually triggered with params.PULL_REQUEST_ID set.
163+
*/
164+
when {
165+
expression { return continue_build }
166+
anyOf {
167+
// env.CHANGE_ID is only set when a build is triggered by a multibranch pipeline job.
168+
expression { env.CHANGE_ID != null }
169+
// params.PULL_REQUEST_ID is set when a build is manually triggered and the parameter is set by the user.
170+
expression { params.PULL_REQUEST_ID != "" }
171+
}
172+
}
173+
steps {
174+
script {
175+
String PULL_REQUEST_ID
176+
// Set pull request ID for standalone builds
177+
PULL_REQUEST_ID = env.CHANGE_ID
178+
}
179+
}
180+
}
181+
stage('Set GLOBAL_BRANCH_NAME') {
182+
/* This stage sets GLOBAL_BRANCH_NAME so that the downstream pipelines can use it.
183+
* The variable is necessary when a build is manually triggered
184+
when {
185+
expression { return continue_build }
186+
expression { env.BRANCH_NAME }
187+
}
188+
}
189+
steps {
190+
script {
191+
/* Check if BRANCH is specified by multibranch pipeline job
192+
env.BRANCH_NAME is only set when a build is triggered by a multibranch pipeline job.
193+
*/
194+
GLOBAL_BRANCH_NAME = env.BRANCH_NAME ?: params.BRANCH
195+
}
196+
}
197+
}
168198
stage("Trigger downstream pipelines") {
169199
when {
170-
expression {
171-
return continue_build
200+
anyOf {
201+
expression { return continue_build }
202+
expression { return params.FORCE_TEST }
172203
}
173204
}
174205
parallel {

.jenkins/pipelines/Agnostic/Linux/Jenkinsfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44
library "OpenEnclaveJenkinsLibrary@${params.OECI_LIB_VERSION}"
55
GLOBAL_ERROR = globalvars.GLOBAL_ERROR
66

7+
/* If a build was triggered with params.PULL_REQUEST_ID set, then we are building a PR.
8+
* In this case, we need to checkout the PR merge head.
9+
* Otherwise we are building a branch and the branch is already checked out by the SCM plugin.
10+
*/
11+
if ( params.PULL_REQUEST_ID != "" ) {
12+
cleanWs()
13+
checkout([$class: 'GitSCM',
14+
branches: [[name: "pr/${PULL_REQUEST_ID}"]],
15+
extensions: [],
16+
userRemoteConfigs: [[
17+
url: 'https://github.com/cyandevs/openenclave',
18+
refspec: "+refs/pull/${PULL_REQUEST_ID}/merge:refs/remotes/origin/pr/${PULL_REQUEST_ID}"
19+
]]
20+
])
21+
}
22+
723
try{
824
def testing_stages = [
925
"Check CI": { tests.checkCI('clang-11') },

.jenkins/pipelines/Azure/Linux/Jenkinsfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44
library "OpenEnclaveJenkinsLibrary@${params.OECI_LIB_VERSION}"
55
GLOBAL_ERROR = globalvars.GLOBAL_ERROR
66

7+
/* If a build was triggered with params.PULL_REQUEST_ID set, then we are building a PR.
8+
* In this case, we need to checkout the PR merge head.
9+
* Otherwise we are building a branch and the branch is already checked out by the SCM plugin.
10+
*/
11+
if ( params.PULL_REQUEST_ID != "" ) {
12+
cleanWs()
13+
checkout([$class: 'GitSCM',
14+
branches: [[name: "pr/${PULL_REQUEST_ID}"]],
15+
extensions: [],
16+
userRemoteConfigs: [[
17+
url: 'https://github.com/cyandevs/openenclave',
18+
refspec: "+refs/pull/${PULL_REQUEST_ID}/merge:refs/remotes/origin/pr/${PULL_REQUEST_ID}"
19+
]]
20+
])
21+
}
22+
723
try{
824
def testing_stages = [
925
"Host verification 2004 RelWithDebInfo": { tests.ACCHostVerificationTest('20.04', 'RelWithDebInfo', 'clang-11') },

.jenkins/pipelines/Azure/Windows/Jenkinsfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44
library "OpenEnclaveJenkinsLibrary@${params.OECI_LIB_VERSION}"
55
GLOBAL_ERROR = globalvars.GLOBAL_ERROR
66

7+
/* If a build was triggered with params.PULL_REQUEST_ID set, then we are building a PR.
8+
* In this case, we need to checkout the PR merge head.
9+
* Otherwise we are building a branch and the branch is already checked out by the SCM plugin.
10+
*/
11+
if ( params.PULL_REQUEST_ID != "" ) {
12+
cleanWs()
13+
checkout([$class: 'GitSCM',
14+
branches: [[name: "pr/${PULL_REQUEST_ID}"]],
15+
extensions: [],
16+
userRemoteConfigs: [[
17+
url: 'https://github.com/cyandevs/openenclave',
18+
refspec: "+refs/pull/${PULL_REQUEST_ID}/merge:refs/remotes/origin/pr/${PULL_REQUEST_ID}"
19+
]]
20+
])
21+
}
22+
723
def testing_stages = [
824
"Windows 2019 Install Prerequisites Verification" : { tests.windowsPrereqsVerify("acc-win2019-dcap") },
925
"ELF Win2019 Ubuntu2004 clang-11 RelWithDebInfo ControlFlow": { tests.windowsLinuxElfBuild(params.WS2019_DCAP_CFL_LABEL, params.UBUNTU_2004_NONSGX_LABEL, 'clang-11', 'RelWithDebInfo', 'ControlFlow') },

0 commit comments

Comments
 (0)