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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:29:28  来源:igfitidea点击:

Jenkins - how to build a specific branch

gitgithubjenkins

提问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,就会构建和部署:

enter image description here

在此处输入图片说明

So if I've just pushed developand 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 branchto feature/my-new-featureand it still pulled from develop.

因此,如果我刚刚推送develop并成功构建,我如何触发手动构建并使其拉动feature/my-new-feature(不执行git push)?我尝试启用参数化构建,添加一个名为 的新字符串branch,然后添加一个新的分支说明符*/$branch. 然后我运行了一个构建并设置branchfeature/my-new-feature,它仍然从develop.

I'd appreciate any help!

我很感激任何帮助!

回答by Ranjith's

Best solution can be:

最佳解决方案可以是:

Add a string parameter in the existing job enter image description here

在现有作业中添加字符串参数 在此处输入图片说明

Then in the Source Code Managementsection update Branches to buildto use the string parameter you defined enter image description here

然后在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 masteras the default branch, and for manual builds it will ask you to enter branch details (FYI: by default it's set to master)enter image description here

图像中指示的配置将告诉 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

enter image description here

在此处输入图片说明

and now you can configure git options:

现在您可以配置 git 选项:

enter image description here

在此处输入图片说明

回答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

enter image description here

在此处输入图片说明

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 enter image description here

将创建一个钩子,然后您可以在选择 github Branches 时从 Jenkins 构建您喜欢的任何分支 在此处输入图片说明

Hope it helps :)

希望能帮助到你 :)

回答by Ashish Chandra

This is extension of answer provided by Ranjith

这是 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 脚本来获取所有分支到活动选择参数中。