简体   繁体   English

Maven使用Jenkins内部版本号安装/部署

[英]Maven install/deploy with Jenkins build number

UPDATE #1 9/18 更新#1 9/18

My company has decided to entirely revamp their development/release cycle to fit a growing number of developers. 我的公司决定彻底改进他们的开发/发布周期,以适应越来越多的开发人员。

The git process will be similar to the successful branching model with a few changes. git进程类似于成功的分支模型 ,只有一些变化。 Instead of developers having direct push access to the "develop" branch, developers would need to make a merge/pull request, requiring code review and basic unit testing. 开发人员需要进行合并/拉取请求,而不是开发人员直接推送访问“开发”分支,需要进行代码审查和基本单元测试。

The version system would be Major.Minor.Patch, where Major versions mark backwards compatibility breaks, Minor versions mark new features and minor bug fixes, and Patch marks critical hot fixes. 版本系统将是Major.Minor.Patch,其中主要版本标记向后兼容性中断,次要版本标记新功能和小错误修复,Patch标记关键热修复。 This new version system will remove the Jenkins build number as a useful piece of information, but attach it to the deployed artifacts for historical purposes. 此新版本系统将删除Jenkins构建号作为有用的信息,但出于历史目的将其附加到已部署的工件。

The "develop" branch will be tracked by Jenkins to build and deploy a SNAPSHOT to our local Nexus, so unreleased but accepted features are available to the developers. Jenkins将跟踪“开发”分支,以构建和部署SNAPSHOT到我们的本地Nexus,因此开发人员可以使用未发布但已接受的功能。 The "master" branch will also be tracked by Jenkins to build and deploy release artifacts. Jenkins还将跟踪“主”分支,以构建和部署发布工件。

The release process would: 发布过程将:

  • Update the POM version based on the released features 根据已发布的功能更新POM版本
  • Git tag the branch with the new version Git使用新版本标记分支
  • Perform unit, integration, and system testing. 执行单元,集成和系统测试。
  • Build, obfuscate, and deploy the release artifacts to our Nexus 构建,混淆并将发布工件部署到我们的Nexus
  • Update the "develop" branch version to "Major.Minor++-SNAPSHOT" for the new development SNAPSHOT. 将“develop”分支版本更新为“Major.Minor ++ - SNAPSHOT”以用于新开发SNAPSHOT。

ORIGINAL POST 原始邮政

I am attempting to build a JAR library that is obfuscated, uses a dynamic build number based on a Jenkins/Hudson build, and is deployed to an in-house Sonatype Nexus. 我正在尝试构建一个混淆的JAR库,使用基于Jenkins / Hudson构建的动态构建号,并部署到内部的Sonatype Nexus。

My issue is that Maven install/deploy does not honor changes to finalName, and setting the version with an expression like the following is considered "bad practice": 我的问题是,Maven install / deploy不会更改finalName,并且使用如下表达式设置版本被视为“不良做法”:

    <version>1.0.${buildNumber}</version>

Despite this being bad practice, it properly installs/deploys the artifacts with the proper version, both local and remote. 尽管这是不好的做法,但它正确地安装/部署具有适当版本(本地和远程)的工件。 The build number is based off of a pair of profiles that are linked to the existence of the build number environment variable of a Jenkins build system, and defaults to 0 in the absence of that variable: 构建号基于一对配置文件,这些配置文件链接到Jenkins构建系统的构建号环境变量的存在,并且在缺少该变量时默认为0:

    <profile>
        <id>static_build_number</id>
        <activation>
            <property>
                <name>!env.BUILD_NUMBER</name>
            </property>
        </activation>
        <properties>
            <buildNumber>0</buildNumber>
        </properties>
    </profile>
    <profile>
        <id>dynamic_build_number</id>
        <activation>
            <property>
                <name>env.BUILD_NUMBER</name>
            </property>
        </activation>
        <properties>
            <buildNumber>${env.BUILD_NUMBER}</buildNumber>
        </properties>
    </profile>

We do not use SNAPSHOT versions, as any version that is committed and pushed to the Nexus is considered a tested release version. 我们不使用SNAPSHOT版本,因为任何提交并推送到Nexus的版本都被视为测试版本。

Is there a "proper" way to set the Maven version based on a Jenkins/Hudson dynamic build number, allowing it to be deployed with that updated version? 是否有一种“正确”的方法来设置基于Jenkins / Hudson动态内部版本号的Maven版本,允许它使用该更新版本进行部署?

The maven way says a version changes only when you release the code, and that two successive builds of the same version, should produce the same output. maven方式表示只有在释放代码时才更改版本,并且相同版本的两个连续版本应该产生相同的输出。

In your case, you're going against those two good practices . 在你的情况下,你反对这两个好的做法

If truly every commit is a new release, then what you're doing doesn't sound terribly wrong (but it does sound funny to me). 如果真的每次提交都是新版本,那么你所做的并不是非常错误(但对我来说听起来很有趣)。 One drawbacks is that it doesn't look like you are createing a tag from your VCS (which is another good practice). 一个缺点是它看起来不像是你从VCS创建一个标签(这是另一个好习惯)。

I'll be honest. 我会说实话。 I can't believe that each commit is a production-ready release. 我无法相信每个提交都是生产就绪版本。 I've never seen this, even in Continuous-Delivery environments, where each commit needs to pass a lot of automated testing and sometimes the revision is rejected (maybe for functional or performance reasons). 我从来没有见过这个,即使在持续交付环境中,每个提交都需要通过大量自动化测试,有时修订被拒绝(可能出于功能或性能原因)。

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

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