@@ -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-
6661pipeline {
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 {
0 commit comments