简体   繁体   English

Jenkins maven将jar部署到nexus - artifact命名

[英]Jenkins maven deploy jar to nexus - artifact naming

My java/maven project called "testproject" is hooked up with my jenkins and nexus repo: 我的java / maven项目叫做“testproject”,它与我的jenkins和nexus repo联系在一起:

My pom.xml looks like: 我的pom.xml看起来像:

....    
<distributionManagement>
    <!-- use the following if you're not using a snapshot version. -->
    <repository>
        <id>nexus</id>
        <name>RepositoryProxy</name>
        <url>http://nexus:8080/nexus/content/repositories/releases</url>
    </repository>
    <!-- use the following if you ARE using a snapshot version. -->
    <snapshotRepository>
        <id>nexus</id>
        <name>RepositoryProxy</name>
        <url>http://nexus:8080/nexus/content/repositories/snapshots</url>
    </snapshotRepository>
</distributionManagement>
......

In my jenkins set up, I have: 在我的jenkins设置中,我有:

Build - maven3 - clean deploy

As expected, jenkins uploads the artifact to Nexus.Look at the console output from jenkins build, as below: 正如预期的那样,jenkins将工件上传到jenkins构建的控制台输出的Nexus.Look,如下所示:

[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ testproject ---
[INFO] Building jar: /var/lib/jenkins/workspace/testproject/target/testproject-0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ testproject ---
[INFO] Installing /var/lib/jenkins/workspace/testproject/target/testproject-0.1-SNAPSHOT.jar to /var/lib/jenkins/.m2/repository/com/dummy/testproject/0.1-SNAPSHOT/testproject-0.1-   SNAPSHOT.jar
[INFO] Installing /var/lib/jenkins/workspace/testproject/pom.xml to /var/lib/jenkins/.m2/repository/com/dummy/testproject/0.1-SNAPSHOT/testproject-0.1-SNAPSHOT.pom
[INFO] 
[INFO] --- maven-deploy-plugin:2.5:deploy (default-deploy) @ testproject ---
Downloading: http://nexus:8080/nexus/content/repositories/snapshots/com/dummy/testproject/0.1-SNAPSHOT/maven-metadata.xml
Downloaded: http://nexus:8080/nexus/content/repositories/snapshots/com/dummy/testproject/0.1-SNAPSHOT/maven-metadata.xml (1012 B at 28.2 KB/sec)
Uploading: http://nexus:8080/nexus/content/repositories/snapshots/com/dummy/testproject/0.1-SNAPSHOT/testproject-0.1-20120509.161644-74.jar
Uploaded: http://nexus:8080/nexus/content/repositories/snapshots/com/dummy/testproject/0.1-SNAPSHOT/testproject-0.1-20120509.161644-74.jar (47 KB at 748.5 KB/sec)
Uploading: http://nexus:8080/nexus/content/repositories/snapshots/com/dummy/testproject/0.1-SNAPSHOT/testproject-0.1-20120509.161644-74.pom
Uploaded: http://nexus:8080/nexus/content/repositories/snapshots/com/dummy/testproject/0.1-SNAPSHOT/testproject-0.1-20120509.161644-74.pom (6 KB at 149.3 KB/sec)

Questions are : 问题是

Given the version I specified in pom.xml is 鉴于我在pom.xml中指定的版本是

<version>0.1-SNAPSHOT</version>
  1. How come jenkins upload testproject- 0.1-20120509.161644-74 .jar to Nexus? 为什么jenkins将testproject- 0.1-20120509.161644-74 .jar上传到Nexus? where is 20120509.161644-74 stuff coming from? 20120509.161644-74来自哪里?

  2. if the timestamp 20120509.161644-74 is generated by jenkins prior to uploading, can I configure the format of it? 如果时间戳20120509.161644-74是由jenkins在上传之前生成的,我可以配置它的格式吗? I want to have something like testproject-01-${timestamp}-${reversionId}.jar 我想要像testproject-01 - $ {timestamp} - $ {reversionId} .jar

The maven deploy plugin page tells that "By default, when a snapshot version of an artifact is deployed to a repository, a timestamp is suffixed to it". maven deploy plugin页面告诉“默认情况下,当工件的快照版本部署到存储库时,时间戳后缀为”。 So, it is created by the plugin when you call mvn deploy . 因此,当您调用mvn deploy时,它是由插件创建的。

I don't know if what you want in 2) is possible. 我不知道你想要的是2)是否可能。 I think it might cause some trouble for maven. 我认为这可能会给maven造成一些麻烦。

When you use maven with SNAPSHOT dependencies, the timestamps are used to check for the most recent version of a SNAPSHOT. 当您使用具有SNAPSHOT依赖项的maven时,时间戳用于检查SNAPSHOT的最新版本。 Changing the format of the snapshots would probably cause this mechanism to fail. 更改快照的格式可能会导致此机制失败。

自Maven 3以来,时间戳在SNAPSHOT版本中添加。使用Maven 2执行时,相同的部署插件不会添加任何时间戳。

That's Maven's way of locking down a version of a snapshot so a specific version can be consumed by another build - it kind of solves the problem, however it has shortcomings. 这是Maven锁定快照版本的方式,因此特定版本可以被另一个版本使用 - 它解决了这个问题,但它有缺点。

I've gone around the houses with snapshots. 我带着快照去了房子。 I believe they are simply evil. 我相信他们只是邪恶。 Build repeatability is a headache as it's tedious to correlate a timestamped snapshot version deployed to the repository with a particular code submission. 构建可重复性是一件令人头疼的事情,因为将部署到存储库的带时间戳的快照版本与特定代码提交相关联非常繁琐。

Save yourselves serious hassle and get your build server to call mvn versions:set -DnewVersion=..${build.number} on you build server prior to building/deploying. 保存自己非常麻烦并让你的构建服务器调用mvn版本:在构建/部署之前,在构建服务器上设置-DnewVersion = .. $ {build.number}。 Tag your source code with the same version. 使用相同版本标记源代码。 If the build fails, it doesn't matter, the build can be configured to refresh the workspace rendering the pom.xml file changes irrelevant. 如果构建失败,则无关紧要,可以将构建配置为刷新工作区,使pom.xml文件的更改无关紧要。

Another typical Maven "gotcha" in using snapshots is that you're not sure precisely which versions of dependencies your pom could be consuming during the build, so make sure your build calls dependency:tree and dependency:list, preceding your other mvn build arguments. 使用快照的另一个典型的Maven“问题”是你不确定你的pom在构建期间可能会消耗哪些版本的依赖项,因此请确保你的构建调用依赖项:树和依赖项:list,在你的其他mvn构建参数之前。 (This will help you identify version inconsistencies of the same artifact during transitive resolution - I swear by the DependencyManagement section in my builds now). (这将帮助您在传递解析期间识别同一工件的版本不一致 - 我现在在我的构建中的DependencyManagement部分发誓)。

While Maven goes a very long way, the "Maven Way" isn't always the best solution. 虽然Maven走了很长的路,但“Maven Way”并不总是最好的解决方案。 It's not quite mature enough for Continuous Delivery best-practices, but you can still work with it effectively, providing you're aware of the pitfalls. 它不是为持续交付最佳实践已经足够成熟,但你可以用它有效地仍然工作,提供你小心上当受骗。

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

相关问题 同时将工件部署到 Maven Central 和内部 Nexus - Simultaneously deploy artifact to Maven Central and internal Nexus Jenkins,Maven,Nexus - 将第三方JAR部署到需要身份验证的Nexus - Jenkins, Maven, Nexus - Deploy 3rd Party JAR to Nexus Where Authentication is Needed 当我将工件通过Maven部署到Nexus时,为什么我的jar文件只包含META-INF目录? - Why does my jar file contains nothing but the META-INF directory, when I deploy my artifact to Nexus by Maven? 您如何将Jenkins中的特定工件部署到Nexus? - How can you deploy a specific artifact from Jenkins into Nexus? Jenkins:如何从 Nexus 检出工件并在 Tomcat 上部署 - - Jenkins : how to check out artifact from Nexus and Deploy on Tomcat- 使用分类器部署工件时,Maven部署到Nexus失败 - Maven Deploy to Nexus Fails When Deploying Artifact with Classifier Maven 将工件部署到 nexus 存储库失败,并出现 gpg 密钥丢失错误 - Maven deploy artifact to nexus repository is failing with gpg key missing errors 是否可以将 maven 多模块项目部署为 Nexus 上的单个工件? - Is it possible to deploy a maven multimodule project as a single artifact on Nexus? Jenkins使用部署到Maven存储库将工件部署到Nexus - Jenkins Deploy Artifacts to Nexus using Deploy to Maven Repository Maven使用Bamboo将非jar文件部署到nexus存储库 - Maven deploy non jar file on to nexus repository using bamboo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM