[英]How to parameterize Git URL in Jenkins Multibranch Pipeline?
Given is a list of repository URLS, which differ in only one part:给定的是存储库 URL 列表,它们仅在一个部分不同:
http://hostname/{A}.git
http://hostname/{B}.git
http://hostname/{C}.git
I want my multibranch pipeline to be able to checkout from a git-repository of my wish.我希望我的多分支管道能够从我希望的 git 存储库中检出。 And I want to be able to choose the repository each time I start the job with "Build with parameters".我希望能够在每次使用“带参数构建”开始工作时选择存储库。
So, I did some parameterization in my Jenkinsfile, like this:所以,我在我的 Jenkinsfile 中做了一些参数化,像这样:
properties(
[
parameters([
choice(name:'repository', choices'A\nB\nC')
]
)
]
)
The question: how do I add the choice variable ( 'repository'
) into the configuration of my Jenkins multibranch build job?问题:如何将选择变量( 'repository'
)添加到我的 Jenkins 多分支构建作业的配置中? In Jenkins GUI under "/configure" I can see "Branch Sources", with the "Git" block, where I can put git-repo URL as "Project Repository".在“/configure”下的 Jenkins GUI 中,我可以看到“Branch Sources”和“Git”块,在那里我可以将 git-repo URL 作为“Project Repository”。 But how can I include the choice into git URL?但是如何将选择包含到 git URL 中?
I have some setup in my jenkins pipeline job.我在 jenkins 管道工作中有一些设置。 Please check if this approach is going to help you.请检查这种方法是否会对您有所帮助。 ################ In my jenkins pipeline groovy job, I defined there parameters. ################ 在我的 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
{
......
}
Now when building job, If I select build with parameters, I can choose the value of the gitrepo from 3 options.现在在构建作业时,如果我选择带参数的构建,我可以从 3 个选项中选择 gitrepo 的值。
Thanks, Subhadeep谢谢,苏哈迪普
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.