在Jenkins管道中使用凭证签出SVN?
如何通过Jenkins管道groovy脚本检出需要用户凭据的Subversion存储库?似乎内置svn
命令不支持凭据,因此我尝试了如下代码:
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)
...
我想念什么?
回答:
您可以将 用于 步骤。这将显示熟悉的Subversion配置选项,并照常将凭据作为参数。
代码段生成器会产生一些难看的参数选择表示,如下所示:
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']])
注意, 部分使用双引号,因此变量$ SVN_BRANCH被正确替换。
以上是 在Jenkins管道中使用凭证签出SVN? 的全部内容, 来源链接: utcz.com/qa/414771.html