如何使用凭据参数设置git凭据

Dua*_*ane 4 jenkins-job-dsl

我正在写一个job-dsl种子作业。种子作业需要能够从github.com或从我公司的github企业服务器中生成。我想保留一份工作,而不是两份。

在每种情况下,我都希望詹金斯获得认证。为此,我将凭据硬编码到了脚本中。但是我对此不满意。我希望在种子作业上添加一个Credentials参数。

问题是,Creds参数似乎将ENV变量添加到包含USERID / PASSWORD的脚本中。 http://steve-jansen.github.io/blog/2014/12/16/parsing-jenkins-secrets-in-a-shell-script/

但是,git jobdsl似乎需要凭据ID,而不是USERID / PASSWORD。

如何解决这种僵局?

scm {
    git {
        remote {
            name('origin')
                url(repo)
                credentials(myCredential)
        }
        branch('master')
    }
}
Run Code Online (Sandbox Code Playgroud)

luk*_*a5z 5

可以在官方Wiki 页面上找到Job DSL处理凭据的方式的很好的介绍。

两个示例说明如何将用户密码传递给Jenkins作业:

// use the github-ci-key credentials for authentication with GitHub 
job('example-1') { 
    scm { 
        git { 
            remote { 
                github('account/repo', 'ssh') 
                credentials('github-ci-key') 
            } 
        } 
    } 
} 

// assign the jarsign-keystore credentials to the PASSWORD build variable job('example-2') { 
    wrappers { 
        credentialsBinding { 
            usernamePassword('PASSWORD', 'jarsign-keystore') 
        } 
    } 
}
Run Code Online (Sandbox Code Playgroud)


Dua*_*ane 0

事实证明,问题的前提是错误的。CredentialsPlugin 1.7 将变量设置为 credentialID。