Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support clone all repo by ssh protocol in testJob (#4228) #4229

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Support clone all repo by ssh protocol in testJob (#4228)
Accelerator1996 committed Jan 29, 2023
commit 46e205ace68fdaa600cc180f2868ae4bacca236a
18 changes: 18 additions & 0 deletions buildenv/jenkins/JenkinsfileBase
Original file line number Diff line number Diff line change
@@ -141,6 +141,15 @@ def setupEnv() {
} else {
sh 'printenv'
}
if ( params.USE_GIT_SSH ) {
def gitGlobalConfig = fileExists('~/.gitconfig') ? sh(script:"git config --global -l", returnStdout:true) : ''
if (!gitGlobalConfig || !gitGlobalConfig.contains('url.git@github.com:.insteadof')) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think overwriting should be fine, no need to check for this condition. Or even better, do git config --local ... to install the preferences on the current cloned directory (Jenkins workspace for the current build)

Local (repository) level configs take precedence over global ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think overwriting should be fine, no need to check for this condition. Or even better, do git config --local ... to install the preferences on the current cloned directory (Jenkins workspace for the current build)

Local (repository) level configs take precedence over global ones.

But --local can only be used inside a git repository. So I think --global can affects all git downloads.

sh "git config --global url.'git@github.com:'.insteadOf 'https://github.com/'"
}
if (!gitGlobalConfig.contains('url.git@gitlab.com:.insteadof')) {
sh "git config --global url.'git@gitlab.com:'.insteadOf 'https://gitlab.com/'"
}
}
}

def setupParallelEnv() {
@@ -805,6 +814,15 @@ def testBuild() {
sh "find /tmp -name '*core*' -print 2>/dev/null -exec rm -f {} \\; || true"
}
}
if ( params.USE_GIT_SSH ) {
def gitGlobalConfig = sh(script:"git config --global -l", returnStdout:true)
if (gitGlobalConfig.contains('url.git@github.com:.insteadof')) {
sh "git config --global --unset url.'git@github.com:'.insteadOf"
}
if (gitGlobalConfig.contains('url.git@gitlab.com:.insteadof')) {
sh "git config --global --unset url.'git@gitlab.com:'.insteadOf"
}
}
}
}
}
2 changes: 2 additions & 0 deletions buildenv/jenkins/testJobTemplate
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@ if (!binding.hasVariable('USER_CREDENTIALS_ID')) USER_CREDENTIALS_ID = ""
if (!binding.hasVariable('GENERATE_JOBS')) GENERATE_JOBS = false
if (!binding.hasVariable('CLOUD_PROVIDER')) CLOUD_PROVIDER = ""
if (!binding.hasVariable('RERUN_ITERATIONS')) RERUN_ITERATIONS = "0"
if (!binding.hasVariable('USE_GIT_SSH')) USE_GIT_SSH = false

if (!binding.hasVariable('BUILDS_TO_KEEP')) {
BUILDS_TO_KEEP = 10
@@ -437,6 +438,7 @@ ARCH_OS_LIST.each { ARCH_OS ->
stringParam('SLACK_CHANNEL', SLACK_CHANNEL, "Slack channel. e.g., #rt-jenkins")
booleanParam('PERSONAL_BUILD', false, "Is this a personal build?")
booleanParam('USE_TESTENV_PROPERTIES', USE_TESTENV_PROPERTIES.toBoolean(), "use properties defined in the testenv.properties")
booleanParam('USE_GIT_SSH', USE_GIT_SSH.toBoolean(), "Use ssh protocol? True, if clone all repo by ssh.")
stringParam('RERUN_ITERATIONS', RERUN_ITERATIONS, "Optional. Number of times to repeat execution of failed test target(s).")
}
cpsScm {