CI: Add https credentials to gerrit checkouts

If the review to be tested is in a project with restricted access,
we need to use the jenkins user's gerrit https credentials when we
do the checkout or the checkout will fail.

Change-Id: I9dc9994763c5ebfeb9f1cff60fb53f6902b7fd5f
This commit is contained in:
George Joseph
2018-08-16 11:08:21 -06:00
parent c2f81cf446
commit 8e1c541acf
2 changed files with 70 additions and 47 deletions

View File

@@ -79,7 +79,13 @@ pipeline {
*
* The Gerrit Trigger provides all the URLs and refspecs to
* check out the change.
*
* We need to retrieve the jenkins2 gerrit https credentials
* in case this review is in a restricted project.
*/
withCredentials([usernamePassword(credentialsId: env.JENKINS_GERRIT_CREDS,
usernameVariable: 'gerrit_user')]) {
checkout scm: [$class: 'GitSCM',
branches: [[name: env.GERRIT_BRANCH ]],
extensions: [
@@ -102,10 +108,15 @@ pipeline {
]
],
userRemoteConfigs: [
[name: env.GERRIT_NAME, refspec: env.GERRIT_REFSPEC, url: env.GERRIT_PROJECT_URL ]
[
credentialsId: env.JENKINS_GERRIT_CREDS,
name: env.GERRIT_NAME,
refspec: env.GERRIT_REFSPEC,
url: env.GERRIT_PROJECT_URL.replaceAll("http(s)?://", "http\$1://${gerrit_user}@")
]
]
]
}
sh "sudo tests/CI/setupJenkinsEnvironment.sh"
}

View File

@@ -80,7 +80,13 @@ pipeline {
*
* The Gerrit Trigger provides all the URLs and refspecs to
* check out the change.
*
* We need to retrieve the jenkins2 gerrit https credentials
* in case this review is in a restricted project.
*/
withCredentials([usernamePassword(credentialsId: env.JENKINS_GERRIT_CREDS,
usernameVariable: 'gerrit_user')]) {
checkout scm: [$class: 'GitSCM',
branches: [[name: env.GERRIT_BRANCH ]],
extensions: [
@@ -103,9 +109,15 @@ pipeline {
]
],
userRemoteConfigs: [
[name: env.GERRIT_NAME, refspec: env.GERRIT_REFSPEC, url: env.GERRIT_PROJECT_URL ]
[
credentialsId: env.JENKINS_GERRIT_CREDS,
name: env.GERRIT_NAME,
refspec: env.GERRIT_REFSPEC,
url: env.GERRIT_PROJECT_URL.replaceAll("http(s)?://", "http\$1://${gerrit_user}@")
]
]
]
}
sh "sudo tests/CI/setupJenkinsEnvironment.sh"
}