使用Jenkins生成Build版本

问题描述 投票:1回答:1

我想找到一种方法在Git中的项目上创建构建标记

我的想法是让詹金斯做标记,如下面的文章所示。

根据这篇文章: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    (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

git jenkins
1个回答
1
投票

你不能改变由詹金斯顺序管理的BUILD_NUMBER

但是,您可以确保您的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.
© www.soinside.com 2019 - 2024. All rights reserved.