简体   繁体   English

如何在 Jenkins Multibranch Pipeline 中参数化 Git URL?

[英]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.

相关问题 如何在 git push 上将自定义参数传递给 jenkins 作业(多分支管道)? - How to pass custom parameters to jenkins job (multibranch pipeline) on git push? Jenkins 多分支管道:如何获取最新的 git 标签? - Jenkins multibranch pipeline: how to get most recent git tag? 如何从Jenkins多分支管道进行Git和Docker标记 - How to do Git & Docker tagging from a Jenkins multibranch pipeline Jenkins 多分支管道 git 配置错误 - Jenkins MultiBranch Pipeline git config error Jenkins多分支管道中的Git commit和push问题 - Git commit and push issue in Jenkins multibranch pipeline 如何在Jenkins管道或Multibranch管道中获取SCM URL? - How do I get the SCM URL inside a Jenkins Pipeline or Multibranch Pipeline? 如何在 jenkins 多分支脚本管道中获取最新的 git 提交作者姓名或消息并在分支条件下使用 - How to get latest git commit author name or message in jenkins multibranch scripted pipeline and use under branch condition Jenkins Multibranch Pipeline 仅检查推送到 GIT 的新文件或更改文件 - Jenkins Multibranch Pipeline check only the new or changed files pushed to GIT GitVersion在Jenkins Multibranch Pipeline工作中 - GitVersion in a Jenkins Multibranch Pipeline job Jenkins 多分支管道与 Jenkinsfile 不在存储库中 - Jenkins Multibranch Pipeline with Jenkinsfile not in repository
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM