Groovy 如何告诉Jenkinsfile使用ssh而不是http来检查输出代码?

Groovy 如何告诉Jenkinsfile使用ssh而不是http来检查输出代码?,groovy,jenkins-workflow,jenkins-pipeline,jenkinsfile,Groovy,Jenkins Workflow,Jenkins Pipeline,Jenkinsfile,使用Jenkinsfile的代码签出似乎是对远程源使用http,我们确实希望使用ssh #!groovy stage 'build' node { checkout scm sh "cat .git/config" } 这将输出https源而不是ssh源。作业是使用github organization pipeline插件配置的,因此无法从jenkins中的作业配置控制源代码。以下是我当前的方法,这很难看,我不打算对此进行辩护 tokens = "${env.JOB_NAM

使用Jenkinsfile的代码签出似乎是对远程源使用http,我们确实希望使用ssh

#!groovy

stage 'build'
node {
    checkout scm
    sh "cat .git/config"
}

这将输出https源而不是ssh源。作业是使用github organization pipeline插件配置的,因此无法从jenkins中的作业配置控制源代码。

以下是我当前的方法,这很难看,我不打算对此进行辩护

tokens = "${env.JOB_NAME}".tokenize('/')
org = tokens[0]
repo = tokens[1]
branch = tokens[2]
sh "git remote set-url origin git@github.com:${org}/${repo}.git"

这是因为github organization plugin生成的作业名称类似于
org/repo/branch

组织文件夹的配置屏幕具有使用特定签出凭据的选项,通常是SSH私钥。默认情况下,它使用API扫描凭据,通常是一个访问令牌,可用于HTTPS签出(GitHub自己的建议)。

仅需了解多分支管道插件的更多详细信息,可在扩展分支源代码的
高级部分后设置签出凭据。如果设置为ssh密钥凭据,则将使用ssh。