Skip to content
Snippets Groups Projects
Commit 8e1c541a authored by George Joseph's avatar George Joseph
Browse files

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
parent c2f81cf4
No related branches found
No related tags found
No related merge requests found
...@@ -79,33 +79,44 @@ pipeline { ...@@ -79,33 +79,44 @@ pipeline {
* *
* The Gerrit Trigger provides all the URLs and refspecs to * The Gerrit Trigger provides all the URLs and refspecs to
* check out the change. * check out the change.
*
* We need to retrieve the jenkins2 gerrit https credentials
* in case this review is in a restricted project.
*/ */
checkout scm: [$class: 'GitSCM', withCredentials([usernamePassword(credentialsId: env.JENKINS_GERRIT_CREDS,
branches: [[name: env.GERRIT_BRANCH ]], usernameVariable: 'gerrit_user')]) {
extensions: [
[$class: 'ScmName', name: 'gerrit-public'], checkout scm: [$class: 'GitSCM',
[$class: 'CleanBeforeCheckout'], branches: [[name: env.GERRIT_BRANCH ]],
[$class: 'PreBuildMerge', options: [ extensions: [
mergeRemote: 'gerrit-public', [$class: 'ScmName', name: 'gerrit-public'],
fastForwardMode: 'NO_FF', [$class: 'CleanBeforeCheckout'],
mergeStrategy: 'RECURSIVE', [$class: 'PreBuildMerge', options: [
mergeTarget: env.GERRIT_BRANCH]], mergeRemote: 'gerrit-public',
[$class: 'CloneOption', fastForwardMode: 'NO_FF',
honorRefspec: true, mergeStrategy: 'RECURSIVE',
noTags: true, mergeTarget: env.GERRIT_BRANCH]],
depth: 10, [$class: 'CloneOption',
shallow: true honorRefspec: true,
noTags: true,
depth: 10,
shallow: true
],
[$class: 'PruneStaleBranch'],
[$class: 'BuildChooserSetting',
buildChooser: [$class: 'GerritTriggerBuildChooser']
]
], ],
[$class: 'PruneStaleBranch'], userRemoteConfigs: [
[$class: 'BuildChooserSetting', [
buildChooser: [$class: 'GerritTriggerBuildChooser'] 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}@")
]
] ]
],
userRemoteConfigs: [
[name: env.GERRIT_NAME, refspec: env.GERRIT_REFSPEC, url: env.GERRIT_PROJECT_URL ]
] ]
] }
sh "sudo tests/CI/setupJenkinsEnvironment.sh" sh "sudo tests/CI/setupJenkinsEnvironment.sh"
} }
......
...@@ -80,32 +80,44 @@ pipeline { ...@@ -80,32 +80,44 @@ pipeline {
* *
* The Gerrit Trigger provides all the URLs and refspecs to * The Gerrit Trigger provides all the URLs and refspecs to
* check out the change. * check out the change.
*
* We need to retrieve the jenkins2 gerrit https credentials
* in case this review is in a restricted project.
*/ */
checkout scm: [$class: 'GitSCM', withCredentials([usernamePassword(credentialsId: env.JENKINS_GERRIT_CREDS,
branches: [[name: env.GERRIT_BRANCH ]], usernameVariable: 'gerrit_user')]) {
extensions: [
[$class: 'ScmName', name: 'gerrit-public'], checkout scm: [$class: 'GitSCM',
[$class: 'CleanBeforeCheckout'], branches: [[name: env.GERRIT_BRANCH ]],
[$class: 'PreBuildMerge', options: [ extensions: [
mergeRemote: 'gerrit-public', [$class: 'ScmName', name: 'gerrit-public'],
fastForwardMode: 'NO_FF', [$class: 'CleanBeforeCheckout'],
mergeStrategy: 'RECURSIVE', [$class: 'PreBuildMerge', options: [
mergeTarget: env.GERRIT_BRANCH]], mergeRemote: 'gerrit-public',
[$class: 'CloneOption', fastForwardMode: 'NO_FF',
honorRefspec: true, mergeStrategy: 'RECURSIVE',
noTags: true, mergeTarget: env.GERRIT_BRANCH]],
depth: 10, [$class: 'CloneOption',
shallow: true honorRefspec: true,
noTags: true,
depth: 10,
shallow: true
],
[$class: 'PruneStaleBranch'],
[$class: 'BuildChooserSetting',
buildChooser: [$class: 'GerritTriggerBuildChooser']
]
], ],
[$class: 'PruneStaleBranch'], userRemoteConfigs: [
[$class: 'BuildChooserSetting', [
buildChooser: [$class: 'GerritTriggerBuildChooser'] 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}@")
]
] ]
],
userRemoteConfigs: [
[name: env.GERRIT_NAME, refspec: env.GERRIT_REFSPEC, url: env.GERRIT_PROJECT_URL ]
] ]
] }
sh "sudo tests/CI/setupJenkinsEnvironment.sh" sh "sudo tests/CI/setupJenkinsEnvironment.sh"
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment