【问题标题】:How to parameterize Git URL in Jenkins Multibranch Pipeline?如何在 Jenkins 多分支管道中参数化 Git URL?
【发布时间】:2020-09-16 14:30:34
【问题描述】:

给出的是存储库 URL 列表,它们仅在一个部分不同:

http://hostname/{A}.git
http://hostname/{B}.git
http://hostname/{C}.git

我希望我的多分支管道能够从我希望的 git 存储库中签出。而且我希望能够在每次使用“使用参数构建”开始工作时选择存储库。

所以,我在我的 Jenkinsfile 中进行了一些参数化,如下所示:

properties(
[
parameters([
choice(name:'repository', choices'A\nB\nC')
]
)
]
)

问题:如何将选择变量 ('repository') 添加到我的 Jenkins 多分支构建作业的配置中?在“/configure”下的 Jenkins GUI 中,我可以看到带有“Git”块的“Branch Sources”,在这里我可以将 git-repo URL 作为“Project Repository”。但是如何将选择包含在 git URL 中?

【问题讨论】:

    标签: git jenkins multibranch-pipeline


    【解决方案1】:

    我在 jenkins 管道工作中有一些设置。 请检查这种方法是否会对您有所帮助。 ################ 在我的詹金斯管道常规工作中,我在那里定义了参数。

    def gitrepo1= "repo 1 url"    
    def gitrepo2= "repo 2 url"
    def gitrepo3= "repo 3 url"
    
    then in pipelinejob function,
    pipelinejob('jobname')
    
    parameters 
    {
    choiceparam('gitrepo',[gitrepo1,gitrepo2,gitrepo3], '')
    ...............................
    ...............................
    }
    definiton 
    {
    ......
    }
    

    现在在构建作业时,如果我选择带参数构建,我可以从 3 个选项中选择 gitrepo 的值。

    谢谢, 深渊

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-23
      • 2018-05-19
      • 2021-11-23
      • 1970-01-01
      相关资源
      最近更新 更多