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

查看:46
本文介绍了如何将 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?

经过深思熟虑,如果在所有构建完成后进行部署,我愿意将所有工件部署到 nexus.如果我要走那条路,我想使用将工件部署到 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.

推荐答案

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

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 时,真正的大问题发生了.我尝试了一个部署文件"目标,但没有一个可以扩展到版本号的变量,我无法指定确切的文件并且通配符不会扩展.相反,我做了一个执行 shell"选项并使用了 curl 我发现 这里:

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天全站免登陆