简体   繁体   English

使用git Commit id在jenkins中参数化构建配置

[英]parameterized build configuraion in jenkins with git Commit id

How can I configure a parametrized build in Jenkins with git Commit id? 如何使用git Commit id在Jenkins中配置参数化构建? I have two parameters: 我有两个参数:

  1. BRANCH_NAME 分店名称
  2. COMMIT_ID COMMIT_ID

I just want to build in Jenkins with Commit Id.... As i can Build with Tag.... 我只想用提交ID构建Jenkins ....因为我可以用标签构建....

Yes you can parameterize your build with two string paramaters (BRANCH_NAME and COMMIT_ID). 是的,您可以使用两个字符串参数(BRANCH_NAME和COMMIT_ID)参数化您的构建。 You should enter a default for the branch, so that whatever branch you use most (hopefully master) is automatically populated. 您应该为分支输入默认值,以便自动填充您最常使用的分支(希望是主分支)。 Defining parameters is discussed in detail here . 这里将详细讨论定义参数。

In the branch specifier section (under branches to build) enter the following: 在分支说明符部分(在要构建的分支下)中输入以下内容:

*/$BRANCH_NAME $COMMIT_ID    

This will make it so instead of "Build" you will have "Build with Parameters". 这将使它成为“Build”而不是“Build”,你将拥有“使用参数构建”。 Manually triggering the build will cause you to be prompted to enter the branch name and commit. 手动触发构建将提示您输入分支名称并提交。 For the commit, you can either enter the whole hash or just the first 7 characters. 对于提交,您可以输入整个哈希值,也可以只输入前7个字符。

TL;DR TL; DR

You can pass the Commit-Id as a parameter in the branch specifier section 您可以将Commit-Id作为参数传递给分支说明符部分

So, the Answer would be: 所以,答案是:

$COMMIT_ID 

在此输入图像描述

LONG ANSWER 长期回答

I wanted to do the same. 我也想这样做。 Allow the user to specify the Branch Name and the Commit Id . 允许用户指定分支名称提交ID I tried the answer provide by @Forest and I was receiving the error: 我尝试了@Forest提供的答案,我收到了错误:

ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job. 

On checking the Help for Branch Specifier , I found that it was possible to pass the Commit Id as a standalone parameter. 在检查分支说明的帮助时,我发现可以将Commit Id作为独立参数传递。

But my concern here was that if I merge two branches, which branch would it pick the commit from (Noob thought). 但我在这里担心的是,如果我合并两个分支,那么它会选择哪个分支(Noob思考)。

A commit actually exists on a single branch. 提交实际上存在于单个分支上。 Even if two branches are merged, the commit is technically part of the original branch it was committed to. 即使合并了两个分支,提交在技术上也是它所承诺的原始分支的一部分。 It is easy to visualise this if you see the flow graph of two merged branches. 如果您看到两个合并分支的流程图,则很容易将其可视化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM