[Asterisk-code-review] CI: Add support for Security-testsuite (testsuite[13])

George Joseph asteriskteam at digium.com
Thu Apr 29 09:30:48 CDT 2021


George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/c/testsuite/+/15846 )


Change subject: CI: Add support for Security-testsuite
......................................................................

CI: Add support for Security-testsuite

Add credentials to the git checkouts so the checkouts
don't fail when the tests are run against Security-testsuite.

Change-Id: If7d242a429e91a7121fc2cd5a9599491b64978d4
---
M CI/gates.jenkinsfile
M CI/unittests.jenkinsfile
2 files changed, 112 insertions(+), 69 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/46/15846/1

diff --git a/CI/gates.jenkinsfile b/CI/gates.jenkinsfile
index fb004e5..9ef33b5 100644
--- a/CI/gates.jenkinsfile
+++ b/CI/gates.jenkinsfile
@@ -82,7 +82,6 @@
 					stage ("Checkout") {
 						sh "sudo chown -R jenkins:users ."
 						env.GERRIT_PROJECT_URL = env.GIT_URL.replaceAll(/[^\/]+$/, env.GERRIT_PROJECT)
-						sh "printenv -0 | sort -z | tr '\\0' '\\n'"
 
 						/*
 						 * Jenkins has already automatically checked out the base branch
@@ -93,32 +92,45 @@
 						 *
 						 * 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.
 						 */
-						checkout scm: [$class: 'GitSCM',
-							branches: [[name: env.GERRIT_BRANCH ]],
-							extensions: [
-								[$class: 'ScmName', name: env.GERRIT_NAME],
-								[$class: 'CleanBeforeCheckout'],
-								[$class: 'PreBuildMerge', options: [
-									mergeRemote: env.GERRIT_NAME,
-									fastForwardMode: 'NO_FF',
-									mergeStrategy: 'RECURSIVE',
-									mergeTarget: env.GERRIT_BRANCH]],
-								[$class: 'CloneOption',
-									honorRefspec: true,
-									noTags: true,
-									shallow: false
-								],
-								[$class: 'PruneStaleBranch'],
-								[$class: 'BuildChooserSetting',
-									buildChooser: [$class: 'GerritTriggerBuildChooser']
-								]
-							],
-							userRemoteConfigs: [
-								[name: env.GERRIT_NAME, refspec: env.GERRIT_REFSPEC, url: env.GERRIT_PROJECT_URL ]
-							]
-						]
+						withCredentials([usernamePassword(credentialsId: "${JENKINS_GERRIT_CREDS}",
+							passwordVariable: 'GERRIT_USER_PW', usernameVariable: 'GERRIT_USER_NAME')]) {
 
+							sh "printenv -0 | sort -z | tr '\\0' '\\n'"
+
+							checkout scm: [$class: 'GitSCM',
+								branches: [[name: env.GERRIT_BRANCH ]],
+								extensions: [
+									[$class: 'ScmName', name: env.GERRIT_NAME],
+									[$class: 'CleanBeforeCheckout'],
+									[$class: 'PreBuildMerge', options: [
+										mergeRemote: env.GERRIT_NAME,
+										fastForwardMode: 'NO_FF',
+										mergeStrategy: 'RECURSIVE',
+										mergeTarget: env.GERRIT_BRANCH]],
+									[$class: 'CloneOption',
+										honorRefspec: true,
+										noTags: true,
+										shallow: false
+									],
+									[$class: 'PruneStaleBranch'],
+									[$class: 'BuildChooserSetting',
+										buildChooser: [$class: 'GerritTriggerBuildChooser']
+									]
+								],
+								userRemoteConfigs: [
+									[
+									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_NAME}@")
+									]
+								]
+							]
+						}
 						sh "sudo CI/setupJenkinsEnvironment.sh --output-dir=CI/output"
 					}
 
@@ -139,18 +151,27 @@
 					img.pull()
 					img.inside(dockerOptions) {
 						def asteriskUrl = env.GERRIT_PROJECT_URL.replaceAll(/\/(Security-)?[^\/]+$/, "/\$1asterisk")
-						checkout scm: [$class: 'GitSCM',
-							branches: [[name: "${BRANCH_NAME}"]],
-							extensions: [
-								[$class: 'RelativeTargetDirectory', relativeTargetDir: astDir],
-								[$class: 'CloneOption',
-									noTags: true,
-									honorRefspec: true,
-									shallow: false
+						withCredentials([usernamePassword(credentialsId: "${JENKINS_GERRIT_CREDS}",
+							passwordVariable: 'GERRIT_USER_PW', usernameVariable: 'GERRIT_USER_NAME')]) {
+							checkout scm: [$class: 'GitSCM',
+								branches: [[name: "${BRANCH_NAME}"]],
+								extensions: [
+									[$class: 'RelativeTargetDirectory', relativeTargetDir: astDir],
+									[$class: 'CloneOption',
+										noTags: true,
+										honorRefspec: true,
+										shallow: false
+									],
 								],
-							],
-							userRemoteConfigs: [[name: env.GERRIT_NAME, url: asteriskUrl]]
-						]
+								userRemoteConfigs: [
+									[
+									credentialsId: env.JENKINS_GERRIT_CREDS,
+									name: env.GERRIT_NAME,
+									url: asteriskUrl.replaceAll("http(s)?://", "http\$1://${GERRIT_USER_NAME}@")
+									]
+								]
+							]
+						}
 
 						stage ('Build') {
 							echo 'Building..'
diff --git a/CI/unittests.jenkinsfile b/CI/unittests.jenkinsfile
index 88bf4c7..c52aeab 100644
--- a/CI/unittests.jenkinsfile
+++ b/CI/unittests.jenkinsfile
@@ -84,7 +84,6 @@
 					stage ("Checkout") {
 						sh "sudo chown -R jenkins:users ."
 						env.GERRIT_PROJECT_URL = env.GIT_URL.replaceAll(/[^\/]+$/, env.GERRIT_PROJECT)
-						sh "printenv -0 | sort -z | tr '\\0' '\\n'"
 
 						/*
 						 * Jenkins has already automatically checked out the base branch
@@ -95,31 +94,45 @@
 						 *
 						 * 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.
 						 */
-						checkout scm: [$class: 'GitSCM',
-							branches: [[name: env.GERRIT_BRANCH ]],
-							extensions: [
-								[$class: 'ScmName', name: env.GERRIT_NAME],
-								[$class: 'CleanBeforeCheckout'],
-								[$class: 'PreBuildMerge', options: [
-									mergeRemote: env.GERRIT_NAME,
-									fastForwardMode: 'NO_FF',
-									mergeStrategy: 'RECURSIVE',
-									mergeTarget: env.GERRIT_BRANCH]],
-								[$class: 'CloneOption',
-									honorRefspec: true,
-									noTags: true,
-									shallow: false
+						withCredentials([usernamePassword(credentialsId: "${JENKINS_GERRIT_CREDS}",
+							passwordVariable: 'GERRIT_USER_PW', usernameVariable: 'GERRIT_USER_NAME')]) {
+
+							sh "printenv -0 | sort -z | tr '\\0' '\\n'"
+
+							checkout scm: [$class: 'GitSCM',
+								branches: [[name: env.GERRIT_BRANCH ]],
+								extensions: [
+									[$class: 'ScmName', name: env.GERRIT_NAME],
+									[$class: 'CleanBeforeCheckout'],
+									[$class: 'PreBuildMerge', options: [
+										mergeRemote: env.GERRIT_NAME,
+										fastForwardMode: 'NO_FF',
+										mergeStrategy: 'RECURSIVE',
+										mergeTarget: env.GERRIT_BRANCH]],
+									[$class: 'CloneOption',
+										honorRefspec: true,
+										noTags: true,
+										shallow: false
+									],
+									[$class: 'PruneStaleBranch'],
+									[$class: 'BuildChooserSetting',
+										buildChooser: [$class: 'GerritTriggerBuildChooser']
+									]
 								],
-								[$class: 'PruneStaleBranch'],
-								[$class: 'BuildChooserSetting',
-									buildChooser: [$class: 'GerritTriggerBuildChooser']
+								userRemoteConfigs: [
+									[
+									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_NAME}@")
+									]
 								]
-							],
-							userRemoteConfigs: [
-								[name: env.GERRIT_NAME, refspec: env.GERRIT_REFSPEC, url: env.GERRIT_PROJECT_URL ]
 							]
-						]
+						}
 
 						sh "sudo CI/setupJenkinsEnvironment.sh --output-dir=CI/output"
 					}
@@ -141,18 +154,27 @@
 					img.pull()
 					img.inside(dockerOptions) {
 						def asteriskUrl = env.GERRIT_PROJECT_URL.replaceAll(/\/(Security-)?[^\/]+$/, "/\$1asterisk")
-						checkout scm: [$class: 'GitSCM',
-							branches: [[name: "${BRANCH_NAME}"]],
-							extensions: [
-								[$class: 'RelativeTargetDirectory', relativeTargetDir: astDir],
-								[$class: 'CloneOption',
-									noTags: true,
-									honorRefspec: true,
-									shallow: false
+						withCredentials([usernamePassword(credentialsId: "${JENKINS_GERRIT_CREDS}",
+							passwordVariable: 'GERRIT_USER_PW', usernameVariable: 'GERRIT_USER_NAME')]) {
+							checkout scm: [$class: 'GitSCM',
+								branches: [[name: "${BRANCH_NAME}"]],
+								extensions: [
+									[$class: 'RelativeTargetDirectory', relativeTargetDir: astDir],
+									[$class: 'CloneOption',
+										noTags: true,
+										honorRefspec: true,
+										shallow: false
+									],
 								],
-							],
-							userRemoteConfigs: [[name: env.GERRIT_NAME, url: asteriskUrl]]
-						]
+								userRemoteConfigs: [
+									[
+									credentialsId: env.JENKINS_GERRIT_CREDS,
+									name: env.GERRIT_NAME,
+									url: asteriskUrl.replaceAll("http(s)?://", "http\$1://${GERRIT_USER_NAME}@")
+									]
+								]
+							]
+						}
 
 						stage ('Build') {
 							echo 'Building..'

-- 
To view, visit https://gerrit.asterisk.org/c/testsuite/+/15846
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: testsuite
Gerrit-Branch: 13
Gerrit-Change-Id: If7d242a429e91a7121fc2cd5a9599491b64978d4
Gerrit-Change-Number: 15846
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210429/3332a831/attachment-0001.html>


More information about the asterisk-code-review mailing list