jenkins - 从 Jenkinsfile 中的 jenkins 作业配置中读取 SVN URL
问题描述
我有一个 Jenkins 管道作业,它被配置为“来自 SCM 的管道脚本”,指向 SVN 中的 Jenkinsfile。例如,SVN URL 是 http://example.com/svn/myproject/trunk/ jenkins master 进行浅层检出(仅根文件),然后在根目录中找到 Jenkinsfile。
此 URL 在 Jenkinsfile 中重复,在该步骤中检出单独的 jenkins 代理上的 SVN 工作区。
因此,每当我为新分支克隆 jenkins 作业时,我需要在两个不同的位置修复 URL:一次在 jenkins 作业配置中,它指向 Jenkinsfile,一次在 Jenkinsfile 中。有没有办法避免这种情况,例如通过从 Jenkinsfile 读取当前作业配置?
解决方案
最后,我设法通过scm
全局从作业配置中检索 SVN URL,将其存储在 SVNURL 环境变量中,然后在结帐步骤中使用它,而不是对 SVN URL 进行硬编码。
stage('stage-name')
{
steps
{
// Get the SVN URL from the pipeline job configuration
script
{
env.SVNURL = scm.getLocations()[0].getURL()
}
checkout([
$class: 'SubversionSCM',
filterChangelog: false,
ignoreDirPropChanges: false,
locations:
[[
credentialsId: '<guid>',
depthOption: 'infinity',
ignoreExternalsOption: false,
local: 'my-checkout-folder',
remote: env.SVNURL
]],
workspaceUpdater: [$class: 'UpdateWithCleanUpdater']
])
}
}
推荐阅读
- symfony - 我怎样才能通过学说获得所有数据,除了一个?
- jquery - ajaxStop 函数在内部是如何工作的?
- birt - BIRT:如何访问 Onprepare() 事件内表中的外表值。?
- scala - Scala 中的 head 字段值还是方法?
- kubernetes - 超时:请求未在允许的时间内完成
- c# - 为 linux 架构发布 .NET Core C# 自包含应用程序
- python - Keras 总是输出一个常数值
- android - Play Store 对我之前购买过我的 Android 应用的用户收取了两次费用
- java - E/Volley:[6681] NetworkDispatcher.processRequest:未处理的异常 java.lang.RuntimeException:错误的 URL null
- r - 遍历行