您如何将Jenkins中的特定工件部署到Nexus中? [英] How can you deploy a specific artifact from Jenkins into Nexus?

查看:258
本文介绍了您如何将Jenkins中的特定工件部署到Nexus中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Jenkins中运行的多模块Maven项目.我想将最终工件(装配体构建中的RPM)部署到Nexus服务器.我认为没有理由部署中间工件(因此没有"mvn clean deploy"),因为这会在我不需要的服务器上产生额外的垃圾.我们正在尝试建立连续的交付渠道,因此我们从未部署过SNAPSHOT版本. Jenkins的各种插件似乎都集中在部署所有工件上.我该如何部署自己选择的那个?

I have a multi-module maven project running in Jenkins. I would like to deploy the final artifact (an RPM from an assembly build) to the Nexus server. I see no reason to deploy intermediate artifacts (hence no "mvn clean deploy") since this will produce extra junk on the server that I don't need. We're trying to set up a continuous delivery pipeline, so we're not deploying SNAPSHOT versions - ever. The various plugins for Jenkins seem focused on deploying all of the artifacts. How can I just deploy the one I choose?

经过深思熟虑,如果部署在所有构建完成之后进行,我愿意将所有工件部署到内部.如果我要走那条路线,我想在构建后使用将工件部署到Maven存储库".不过,此工具似乎已损坏,因为它缺少指定用户名/密码的功能.我知道可以在settings.xml中指定它,但显然只有".m2"中的一个.似乎并没有查看我为此版本指定的settings.xml.

After much consideration, I'd be willing to deploy all the artifacts to nexus if the deploy happens after all of the build has completed. If I was going that route, I'd want to use the "Deploy artifacts to maven repository" post build action. This tool seems broken though because it's missing the functionality of specifying the username/password. I know this can be specified in the settings.xml, but apparently only the one in ".m2". It doesn't seem to be looking at the settings.xml I specified for this build.

这似乎也因为重新部署工件而被破坏了.有一些

This also seems like it's broken for redeploying artifacts. There is some verbage in "Jenkins the Definitive Guide" for this, but it talks about a "local" settings.xml. All my builds are happening on Jenkins slaves, so this isn't an option and doesn't even really make sense with the Jenkins architecture.

推荐答案

这是我想到的丑陋的方法.如果有人有更好的主意,我会很乐意为其他人提供正确"的答案:

Here's the ugly hack I came up with. I'll gladly give someone else the "correct" answer for this if anyone has a better idea:

我意识到我需要同时部署父pom.xml和程序集.我是在两个单独的后期制作步骤中完成的.

I realized that I need to deploy both the parent pom.xml and the assembly. I did this in two separate post build steps.

首先,我选择了调用顶级Maven目标"以及Maven版本的"Maven"(我认为它使用Jenkins版本的maven.我不想在系统上放置其他版本).我使用了以下目标:

First, I chose "Invoke top-level Maven targets" with a Maven Version of "Maven" (I think this uses Jenkins version of maven. I don't want to put a different version on the system). I used Goals of:

-s svn-admin/settings.xml -N deploy

使用我指定的settings.xml,仅将父pom部署到nexus.

That deploys just the parent pom to nexus with my specified settings.xml.

当我想部署rpm时,确实发生了很大的变化.我尝试了部署文件"目标,但是如果没有变量,我可以扩展到版本号,我无法指定确切的文件,而通配符也不会扩展.取而代之的是,我做了一个执行外壳"选项并使用了卷曲,我发现

The REALLY big hack happens when I want to deploy the rpm. I tried a "deploy-file" target, but without a variable I could expand to the version number, I couldn't specify the exact file and wildcards don't expand. Instead I did an "Execute shell" option and used curl I found here:

env
UPLOAD_FILE=assembly/target/ips-${POM_VERSION}-x.x86_64.rpm
DESTINATION=http://mvnrepo01/nexus/content/repositories/releases/com/bla/ips/assembly/${POM_VERSION}/assembly-${POM_VERSION}.rpm
sha1sum ${UPLOAD_FILE} | awk -F" " '{print $1}' | curl -v -u admin:password --upload-file - ${DESTINATION}.sha1
md5sum ${UPLOAD_FILE} | awk -F" " '{print $1}' | curl -v -u admin:password --upload-file - ${DESTINATION}.md5
curl -v -u admin:password --upload-file ${UPLOAD_FILE} ${DESTINATION}

UPLOAD_FILE=assembly/pom.xml
DESTINATION=http://mvnrepo01/nexus/content/repositories/releases/com/bla/ips/assembly/${POM_VERSION}/assembly-${POM_VERSION}.pom
sha1sum ${UPLOAD_FILE} | awk -F" " '{print $1}' | curl -v -u admin:password --upload-file - ${DESTINATION}.sha1
md5sum ${UPLOAD_FILE} | awk -F" " '{print $1}' | curl -v -u admin:password --upload-file - ${DESTINATION}.md5
curl -v -u admin:password --upload-file ${UPLOAD_FILE} ${DESTINATION}

就像我说的那样,这是一个丑陋的骇客.我很确定有些元数据文件没有更新,但是rpm,pom和它们的校验和都已上传.

Like i said, this is an ugly hack. I'm pretty sure there are metadata files that aren't getting updated, but the rpm, it's pom, and their checksums are getting uploaded.

这篇关于您如何将Jenkins中的特定工件部署到Nexus中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆