如何使用 jenkins git 插件从分支构建包含源与否
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6498238/
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
How to use jenkins git plugin to build from a branch include origin or not
提问by Peter Kahn
When building from git on master jenkins fetches and uses origin/master. When building from git on a branch jenkins fetches and users mybranch not origin/mybranch and isn't picking up changes.
在 master 上从 git 构建时,jenkins 获取并使用 origin/master。当在分支上从 git 构建时,jenkins 获取并且用户 mybranch 不是 origin/mybranch 并且没有获取更改。
I switched the branch specifier to use origin/mybranchand it seems to work. Is the the standard way to handle things or am I missing a more obvious way of doing this? I don't want to add unecessary complexity.
我将分支说明符切换为使用origin/mybranch,它似乎有效。是处理事情的标准方法还是我错过了更明显的方法?我不想增加不必要的复杂性。
Please let me know if jenkins should use origin/branchname instead of branchname for its Branches-To-Build field.
请让我知道 jenkins 是否应该在其 Branches-To-Build 字段中使用origin/branchname 而不是 branchname 。
Thanks
谢谢
Peter
彼得
采纳答案by adam.kuyrkendall
Check your current .git/config, and you will see that your "origin" and how master relates to origin is already specified. No other branches will be specified, so the plugin can't construct a url. To add further branches...
检查您当前的 .git/config,您将看到您的“来源”以及 master 与来源的关系已被指定。不会指定其他分支,因此插件无法构建 url。要添加更多分支...
[remote "origin"]
url = ssh://myserv/srv/git/proj.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[branch "im_a_branch"]
remote = origin
merge = refs/heads/im_a_branch_remote_branch_name
This would enable you to just put in the branch name in the branches to build field in Jenkins. That's probably overkill, and extra maintenance. Just put in the origin/branchname.
这将使您只需在分支中输入分支名称即可在 Jenkins 中构建字段。这可能是矫枉过正,需要额外的维护。只需输入来源/分支名称。
回答by Laepdjek
If you only have one remote repository (named origin
), then entering branchname
should be synonymous with entering origin/branchname
. If you have multiple repositories and you just enter branchname
then it should be checking all of the remote repositories for that branch.
如果您只有一个远程存储库(名为origin
),则输入branchname
应与输入同义origin/branchname
。如果您有多个存储库并且您只是输入,branchname
那么它应该检查该分支的所有远程存储库。
Note that if you manually created a branch named branchname
in the Jenkins workspace repository, then it may have slightly strange behavior, and you'll probably want to delete that branch or recreate the workspace. In general you should never manually manipulate the branches in the workspace repository.
请注意,如果您手动创建了一个branchname
在 Jenkins 工作区存储库中命名的分支,那么它的行为可能会有些奇怪,您可能想要删除该分支或重新创建工作区。通常,您永远不应该手动操作工作区存储库中的分支。
It should never be trying to use local (non-remote) branches for polling or getting changes. If you are seeing it do this, then it's definitely a bug. You should try to upgrade your jenkins instance and git plugin to the newest version, and if you still see the problem you should file an issue(and in the meantime you could use origin/branchname
as a workaround). However, entering just branchname
works fine for me with the latest version, so if you continue to see this problem I would recommend you recreate the workspace to try to get a clean repository.
它永远不应该尝试使用本地(非远程)分支进行轮询或获取更改。如果您看到它这样做,那么这绝对是一个错误。你应该尝试将你的 jenkins 实例和 git 插件升级到最新版本,如果你仍然看到问题,你应该提交一个问题(同时你可以origin/branchname
作为一种解决方法)。但是,branchname
使用最新版本输入对我来说很好用,所以如果您继续看到这个问题,我建议您重新创建工作区以尝试获得一个干净的存储库。