git Jenkins - 如何建立一个特定的分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32108380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jenkins - how to build a specific branch
提问by ffxsam
This isn't as simple as just doing a parametrized build. I've already got a specific build process that will build and deploy whenever any of these branches are pushed to GitHub:
这并不像仅仅进行参数化构建那么简单。我已经有了一个特定的构建过程,只要将这些分支中的任何一个推送到 GitHub,就会构建和部署:
So if I've just pushed develop
and it built successfully, how do I trigger a manual build and have it pull feature/my-new-feature
(without doing a git push
)? I tried enabling parametrized build, adding a new string called branch
, and then adding a new branch specifier, */$branch
. I then ran a build and set branch
to feature/my-new-feature
and it still pulled from develop
.
因此,如果我刚刚推送develop
并成功构建,我如何触发手动构建并使其拉动feature/my-new-feature
(不执行git push
)?我尝试启用参数化构建,添加一个名为 的新字符串branch
,然后添加一个新的分支说明符*/$branch
. 然后我运行了一个构建并设置branch
为feature/my-new-feature
,它仍然从develop
.
I'd appreciate any help!
我很感激任何帮助!
回答by Ranjith's
Best solution can be:
最佳解决方案可以是:
Add a string parameter in the existing job
Then in the Source Code Management
section update Branches to build
to use the string parameter you defined
然后在Source Code Management
更新部分Branches to build
中使用您定义的字符串参数
If you see a checkbox labeled Lightweight checkout
, make sure it is unchecked.
如果您看到标记为 的复选框Lightweight checkout
,请确保未选中它。
The configuration indicated in the images will tell the jenkins job to use master
as the default branch, and for manual builds it will ask you to enter branch details (FYI: by default it's set to master
)
图像中指示的配置将告诉 jenkins 作业master
用作默认分支,对于手动构建,它会要求您输入分支详细信息(仅供参考:默认情况下设置为master
)
回答by smohamed
I don't think you can both within the same jenkins job, what you need to do is to configure a new jenkins job which will have access to your github to retrieve branches and then you can choose which one to manually build.
我不认为你可以在同一个 jenkins 工作中,你需要做的是配置一个新的 jenkins 工作,它可以访问你的 github 来检索分支,然后你可以选择手动构建哪个。
Just mark it as a parameterized build, specify a name, and a parameter configured as git parameter
只需将其标记为参数化构建,指定名称,并将参数配置为 git parameter
and now you can configure git options:
现在您可以配置 git 选项:
回答by Igor L.
To checkout the branch via Jenkins scripts use:
要通过 Jenkins 脚本签出分支,请使用:
stage('Checkout SCM') {
git branch: 'branchName', credentialsId: 'your_credentials', url: "giturlrepo"
}
回答by rohit thomas
There will be an option in configure under Build Triggers
在 Build Triggers 下的 configure 中会有一个选项
Check the GitHub Branches
检查 GitHub 分支
A hook will be created and then you can build any branch you like from Jenkins when you select github Branches
将创建一个钩子,然后您可以在选择 github Branches 时从 Jenkins 构建您喜欢的任何分支
Hope it helps :)
希望能帮助到你 :)
回答by Ashish Chandra
This is extension of answer provided by Ranjith
I would suggest, you to choose a choice-parameter build, and specify the branches that you would like to build. Active Choice Parameter
我建议您选择一个选择参数构建,并指定您想要构建的分支。 主动选择参数
And after that, you can specify branches to build. Branch to Build
之后,您可以指定要构建的分支。 分支构建
Now, when you would build your project, you would be provided with "Build with Parameters, where you can choose the branch to build"
现在,当您构建项目时,您将获得“带参数构建,您可以在其中选择要构建的分支”
You can also write a groovy script to fetch all your branches to in active choice parameter.
您还可以编写一个 groovy 脚本来获取所有分支到活动选择参数中。