使用 Jenkins 管道中的凭据签出 SVN? [英] Checkout SVN with credentials in Jenkins pipeline?

查看:26
本文介绍了使用 Jenkins 管道中的凭据签出 SVN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过 Jenkins 管道 groovy 脚本检出需要用户凭据的 Subversion 存储库?似乎内置的 svn 命令不支持凭据,所以我尝试了这样的代码:

How can I check out a Subversion repository that requires user credentials, via a Jenkins pipeline groovy script? It appears that the built-in svn command doesn't support credentials, so I tried code like this:

node {
    stage 'checkout'
    withCredentials([[$class: 'UsernamePasswordMultiBinding',
                      credentialsId: '34761a89-1402-47d7-96e2-aec22ffdc50b',
                      usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
        sh "svn co https://trac.nci.org.au/svn/cable/branches/$SVN_BRANCH --username $USERNAME --password $PASSWORD cable_branch"
    }
}

但这失败了

groovy.lang.MissingPropertyException: No such property: USERNAME for class: groovy.lang.Binding
    at groovy.lang.Binding.getVariable(Binding.java:63)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:224)
    at org.kohsuke.groovy.sandbox.impl.Checker$4.call(Checker.java:241)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:238)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:221)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:221)
    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:23)
    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:17)
    at WorkflowScript.run(WorkflowScript:5)
    at ___cps.transform___(Native Method)
    ...

我错过了什么?

推荐答案

您可以使用 Snippet Generator 进行 General SCM 步骤.这将显示熟悉的 Subversion 配置选项,并像往常一样将凭据作为参数.

You can use the Snippet Generator for General SCM step. This displays the familiar Subversion configuration options, and takes credentials as parameter as usual.

Snippet Generator 会生成一个有点丑陋的参数选择表示,看起来像这样:

The Snippet Generator will produce a tad ugly representation of your parameter selections and looks something like this:

checkout([$class: 'SubversionSCM', 
          additionalCredentials: [], 
          excludedCommitMessages: '', 
          excludedRegions: '', 
          excludedRevprop: '', 
          excludedUsers: '', 
          filterChangelog: false, 
          ignoreDirPropChanges: false, 
          includedRegions: '', 
          locations: [[credentialsId: '34761a89-1402-47d7-96e2-aec22ffdc50b', 
                       depthOption: 'infinity', 
                       ignoreExternalsOption: true, 
                       local: 'cable_branch', 
                       remote: "https://trac.nci.org.au/svn/cable/branches/$SVN_BRANCH"]], 
          workspaceUpdater: [$class: 'UpdateUpdater']])

请注意,remote 部分使用双引号,以便正确替换变量 $SVN_BRANCH.

Notice that the remote section uses double quotes, so that the variable $SVN_BRANCH gets substituted correctly.

这篇关于使用 Jenkins 管道中的凭据签出 SVN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆