使用 Hudson 构建特定的 git commit

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4207450/
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-10 09:30:31  来源:igfitidea点击:

Use Hudson to build a specific git commit

githudson

提问by Bernd

I have a hudson build server. The source code is managed by a git repository. For each build the latest version is checked out and compiled. Now i'd like to tell hudson to use not the latest version, but an older version of the code (specified by me).

我有一个 hudson 构建服务器。源代码由 git 存储库管理。对于每个构建,都会检出并编译最新版本。现在我想告诉 hudson 不要使用最新版本,而是使用旧版本的代码(由我指定)。

In hudson i have two parameters which can be set. First "name of repository", with default value "origin" and second refspecwith value +refs/heads/*:refs/remotes/origin/*. I tried a bit around something like origin/[commitid]or +refs/heads/*:refs/remotes/origin/[commitid]. But nothing worked as expected.

在哈德森我有两个可以设置的参数。第一个“存储库名称”,默认值为“origin”,第二个refspec值为 value +refs/heads/*:refs/remotes/origin/*。我尝试了一些类似origin/[commitid]或的东西+refs/heads/*:refs/remotes/origin/[commitid]。但没有任何工作如预期。

I think i had to use a parameterized job, so that i can give the commit as parameter to the job.

我想我必须使用参数化作业,以便我可以将提交作为作业的参数。

How can i tell hudson to use a specific commit instead of the latest one?

我如何告诉 hudson 使用特定的提交而不是最新的提交?

回答by izzekil

I just want to thisanswer more clear. How to make your job to checkout a specific commit, step by step:

我只是想让这个答案更清楚。如何让你的工作检查特定的提交,一步一步:

  1. Add string parameter to your job with name, let it be COMMITin my example.
  2. Choose Git as SCM (provided by Jenkins Git plugin).
  3. In Git SCM properties set your repo properties.
  4. In Git SCM, in the paragraph Branches to buildtype ${COMMIT}which is the reference to the job parameter and will be resolved during the build.
  1. 使用名称将字符串参数添加到您的作业中,COMMIT在我的示例中。
  2. 选择 Git 作为 SCM(由Jenkins Git 插件提供)。
  3. 在 Git SCM 属性中设置你的 repo 属性。
  4. 在 Git SCM 中,在Branches to buildtype段落中${COMMIT}这是对作业参数的引用,将在构建期间解析。

That's it, launch the build and in the log you will see something like this:

就是这样,启动构建并在日志中您将看到如下内容:

Cloning the remote Git repository
Cloning repository ssh://your-repo.git
Fetching upstream changes from ssh://your-repo.git
using GIT_SSH to set credentials 
Fetching upstream changes from ssh://your-repo.git
using GIT_SSH to set credentials 
Checking out Revision af63e2102b65953316e512c0bb659578bb143a33 (detached)

Note, that there are other ways to set the environment variable before the SCM checkout, i.e. using Prepare environment for the runstep from the EnvInject Plugin(you could even use Groovy for this).

请注意,还有其他方法可以在 SCM 检出之前设置环境变量,即使用EnvInject 插件中的Prepare environment for the run步骤(您甚至可以为此使用 Groovy)。

Also, if you don't see the options I'm talking about or they don't work, ensure you have a new version of a Git plugin In my case it is 2.2.0.

另外,如果您没有看到我所说的选项或它们不起作用,请确保您有一个新版本的 Git 插件在我的情况下它是 2.2.0。

回答by lkimmel

You can use the branch parameter of the jenkins-git-pluginto define a specific commit id.

您可以使用jenkins-git-plugin的 branch 参数来定义特定的提交 ID。

Jenkins will then only checkout that commit and not the head of a branch.

Jenkins 将只签出该提交而不是分支的负责人。

回答by linkaipeng

Like the documentation says:

就像文档说的:

git plugin branch configure

git插件分支配置

Input your commit id to the "Branches to build" setting.

将您的提交 ID 输入到“要构建的分支”设置中。

回答by Andrzej Jozwik

In "Pre Steps" try to add "Execute shell" and add:

在“Pre Steps”中尝试添加“Execute shell”并添加:

   git pull
   git checkout <commit version>

回答by VonC

One workaround would be to:

一种解决方法是:

  • set the Git plugin to build a special "build_br" branch.
  • reset the branch build_brto the expected commit
  • push that branch build_brto remote repo monitor by Jenkins or Hudson (that would be a push --force, as illustrated in "git reset --hardand a remote repository")
  • 设置 Git 插件来构建一个特殊的“ build_br”分支。
  • 将分支重置build_br为预期的提交
  • 将该分支推build_br送到 Jenkins 或 Hudson的远程仓库监视器(这将是一个push --force,如“git reset --hard和远程存储库”所示)

That way, building that branch build_brwould mean building a specific commit, and the GIT_COMMIT will be correctly set.
No development should take place on that special branch, since it is reset regularly to any commit you need to be build.

这样,构建该分支build_br将意味着构建特定的提交,并且 GIT_COMMIT 将被正确设置。
不应在该特殊分支上进行任何开发,因为它会定期重置为您需要构建的任何提交。

回答by Dave Bacher

You can configure your Hudson job to build a specific branch. Then you can push whatever changes you want Hudson to build onto that branch.

您可以配置您的 Hudson 作业以构建特定分支。然后,您可以将您希望 Hudson 构建的任何更改推送到该分支上。

回答by sschuberth

I'm not sure about Hudson, but Jenkins' Git Plugin has an "Advanced..." button at the right just above the "Repository browser" field. Clicking there reveals a lot of additional options, one of them being "Checkout/merge to local branch (optional)". Its help text says "If given, checkout the revision to build as HEAD on this branch. Please note that this has not been tested with submodules", so that seems to be what you have in mind.

我不确定 Hudson,但 Jenkins 的 Git 插件在“存储库浏览器”字段正上方的右侧有一个“高级...”按钮。单击那里会显示许多其他选项,其中之一是“结帐/合并到本地分支(可选)”。它的帮助文本说“如果给出,请检查修订版以在此分支上构建为 HEAD。请注意,这尚未使用子模块进行测试”,因此这似乎是您的想法。