【问题标题】:using Jenkins to generate Build Version使用 Jenkins 生成构建版本
【发布时间】:2017-12-31 01:22:01
【问题描述】:

我正在想办法在 Git 中的项目上创建构建标签

我的想法是让 Jenkins 进行如下文章所示的标记。

根据这篇文章: http://www.nailedtothex.org/roller/kyle/entry/configuring-automatic-push-by-successfully

我的理解是版本号要通过以下方式生成:

(Major version).(Minor version).(Revision number).(Build number)

1.2.3 (11BCF) <- Build number, should correspond with a revision in source control
^ ^ ^
| | |
| | +--- Minor bugs, spelling mistakes, etc.
| +----- Minor features, major bug fixes, etc.
+------- Major version, UX changes, file format changes, etc.

根据此消息: https://softwareengineering.stackexchange.com/questions/3199/what-version-naming-convention-do-you-use

我的项目有 4 个级别,即 PRODUCTION、TEST、CONSOLIDATION、DEVELOPMENT。

版本看起来像

 PRODUCTION    (generate deploy build only if major/minor/revision number changes)
     ^         (send to STABLE repository)
     |
   TEST        (generate deploy build only if major/minor/revision number changes)
     ^
     |
CONSOLIDATION  (generate all of the time)
     ^
     |
DEVELOPMENT    (generate all of the time)

如何修复 $BUILD_NUMBER 以便它 ($BUILD_NUMBER) 是根据以下方式生成的: (主要版本)。(次要版本)。(修订号)。(内部版本号)

我可以将什么传递给 Jenkins 作业(在配置期间),以便它识别 (主要版本)。(次要版本)。(修订号)

有没有更好的方法来实现这一点?

TIA

【问题讨论】:

  • BUILD_NUMBER 是 Jenkins 构建过程的一部分,并且在工作开始时自动生成,我认为您在某种程度上指的是 Jenkins 管道更多控制流的东西,比如 SCM 标记,或者版本号更改。
  • 不确定您使用哪种语言,但每个构建工具也可以促进版本号管理流程。

标签: git jenkins


【解决方案1】:

您无法更改 BUILD_NUMBER,由 Jenkins 按顺序管理。

但是您可以确保您的 Jenkins 作业构建步骤之一生成一个标签(遵循 semver convention),然后最后一次重新编译您的项目,并使用这些版本信息生成一个属性文件。

见“Applying the existing tag on a new commit in Git”。

这使用了ktoso/maven-git-commit-id-plugin maven 插件。
它允许您的项目在运行时引用此生成的属性(键/值)文件,您可以在其中找到 X.Y.Z 以及 Git SHA1。
该插件将为您运行git describe

描述结果的格式定义为:

v1.0-2-g2414721-DEV
 ^   ^  ^       ^
 |   |  |       \-- if a dirtyMarker was given, it will appear here if the repository is in "dirty" state
 |   |  \---------- the "g" prefixed commit id. The prefix is compatible with what git-describe would return - weird, but true.
 |   \------------- the number of commits away from the found tag. So "2414721" is 2 commits ahead of "v1.0", in this example.
 \----------------- the "nearest" tag, to the mentioned commit.

【讨论】:

  • 感谢您的回复。我将在使用 Java 和 Maven 时使用它 :-) 到目前为止,我正在使用 Python 和 DJango。来自 Python / Django 的代码已被推送到 Git 存储库中。 Python / DJango 代码已在 Jenkins 下签出,以创建 Docker 映像。我希望生成一个发布版本,以便它可以 1)应用于 Docker 映像的 Docker 标记和 2)将相同的标记应用于制作 Docker 映像时涉及的 Git 存储库(Python/DJango)。 Maven 插件在这种情况下也能工作吗?再次感谢您的回复!
  • @CaseyHarrils 当然可以,因为 git describe 可用于生成 Docker 和 Git 都使用的标签。如果你不使用 maven,你仍然可以为此调用 git describe。
  • 再次感谢您提供的信息。将尝试并使用 TIA 的结果进行更新
猜你喜欢
  • 2019-03-13
  • 1970-01-01
  • 2018-10-26
  • 2012-09-05
  • 2019-06-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-02
相关资源
最近更新 更多