Jenkins Git 插件在构建作业之前未提取最新更改
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25774895/
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 Git Plugin not pulling latest changes before building job
提问by polarice
I am working with Jenkins CI and am trying to properly configure my jobs to use git.
我正在使用 Jenkins CI 并尝试正确配置我的作业以使用 git。
I have the git plugin installed and configured for one of my jobs. When I build the job, I expect it to pull the latest changes for the branch I specify and then continue with the rest of the build process (e.g., unit tests, etc.).
我为我的一项工作安装并配置了 git 插件。当我构建作业时,我希望它为我指定的分支提取最新的更改,然后继续构建过程的其余部分(例如,单元测试等)。
When I look at the console output, I see
当我查看控制台输出时,我看到
> git fetch --tags --progress ssh://gerrit@git-dev/Util +refs/heads/*:refs/remotes/origin/*
> git rev-parse origin/some_branch^{commit}
Checking out Revision <latest_SHA1> (origin/some_branch)
> git config core.sparsecheckout
> git checkout -f <latest_SHA1>
> git rev-list <latest_SHA1>
I see that the plugin fetches and checks out the proper commit hash, but when the tests run it seems as though the repo wasn't updated at all. If I go into the repository in Jenkins, I see there that the latest changes were never pulled.
我看到插件获取并检查了正确的提交哈希,但是当测试运行时,似乎 repo 根本没有更新。如果我进入 Jenkins 的存储库,我会在那里看到最新的更改从未被提取。
Shouldn't it pull before it tries to build?
它不应该在尝试构建之前拉动吗?
I have git 1.8.5 installed on my Jenkins machine, which is a recommended version. https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin
我的 Jenkins 机器上安装了 git 1.8.5,这是推荐版本。 https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin
After checking other similar sounding questions on SO, their answers weren't helpful for my problem.
在检查了其他类似的问题后,他们的回答对我的问题没有帮助。
采纳答案by bpgriner
I believe Jenkins pulls the changes and builds in it's own tmp directory. So, your repository directory isn't getting updated although Jenkins is properly building the new code in it's own sandbox.
我相信 Jenkins 会提取更改并在它自己的 tmp 目录中构建。因此,尽管 Jenkins 在其自己的沙箱中正确构建了新代码,但您的存储库目录并未更新。
My solution to this has been to add a "git pull" step in my build process like so:
我对此的解决方案是在我的构建过程中添加一个“git pull”步骤,如下所示:
When a new commit is delivered to my GitHub repo:
1. Build my project
当一个新的提交被传送到我的 GitHub 存储库时:
1. 构建我的项目
If successful, perform the following post-build steps:
1. Execute Shell:
如果成功,请执行以下构建后步骤:
1. 执行 Shell:
cd /your/repo/directory/
git pull
You can obviously modify the "git pull" command to do whatever you need to do if a 'pull' doesn't work for you.
如果“拉”对您不起作用,您显然可以修改“git pull”命令以执行您需要执行的任何操作。
回答by Abhijeet
Relates me to scenario where workspace wasn't getting cleaned-up, used:
将我与工作区未清理的场景相关,使用:
Source Code Management--> Additional Behaviours --> Clean after checkout
Other option is to use Workspace Cleanup Plugin
其他选项是使用工作区清理插件
回答by Krishna Gupta
回答by Harish Talanki
I know the question is old, but there is another way to do this. In the Build Environmentsection, select "Delete workspace before build starts"
我知道这个问题很老,但还有另一种方法可以做到这一点。在构建环境部分,选择“构建开始前删除工作空间”
See the screenshot below,
看下面的截图,
This will actually clean the workspace every time and hence you will get the updated code.
这实际上每次都会清理工作区,因此您将获得更新的代码。
回答by Francesco Santagati
Try to insert your branch path with this format:
尝试使用以下格式插入分支路径:
refs/remotes/<remoteRepoName>/<branchName>
Tracks/checks out the specified branch.
E.g. refs/remotes/origin/master
回答by MassiveConfusion
Simply tick the check box in the image.. cheers This Tab saved me the Head aches
只需勾选图像中的复选框.. 欢呼 这个标签救了我头疼