【问题标题】:Read SVN URL from jenkins job configuration, from within Jenkinsfile从 Jenkinsfile 中的 jenkins 作业配置中读取 SVN URL
【发布时间】:2020-05-26 16:26:54
【问题描述】:

我有一个 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 中读取当前作业配置?

【问题讨论】:

  • 不确定是否要读取相同作业的配置,但是,这可以通过参数化 URL 来完成。一旦它作为参数传递,同样可以馈送到 SCM 并可以在 Jenkinsfile 中使用。
  • @saurabh14292 我找到了一种无需参数化的方法,请参阅下面的答案
  • @saurabh14292 你好,我试了很多方法,为什么不能从SCM的管道脚本中参数化svn url,比如${SVN_URL}、$SVN_URL等无效,你能帮帮我吗?

标签: jenkins jenkins-pipeline


【解决方案1】:

最后,我设法通过 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']
        ])
    }
}

【讨论】:

  • 您好,每次添加新分支时,都需要在jenkins ui的SCM的管道脚本中添加一个svn new url。是多余的吗?有没有办法参数化svn url?当我构建某个参数时,他只是在那个url中找到jenkinsfile
猜你喜欢
  • 2017-11-14
  • 1970-01-01
  • 2013-11-24
  • 2017-10-18
  • 1970-01-01
  • 2017-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多