简体   繁体   English

Artifactory + Jenkins:从自由式构建发布到maven存储库

[英]Artifactory + Jenkins: Publishing to a maven repository from a freestyle build

I have a Jenkins freestyle build, based on a Scala project using SBT. 我有一个Jenkins自由式构建,基于使用SBT的Scala项目。 I'm trying to use the Jenkins Artifactory plugin to publish the resulting artifacts to an Artifactory repository, specifically one hosted at artifactoryonline.com. 我正在尝试使用Jenkins Artifactory插件将生成的工件发布到Artifactory存储库,特别是在artifactoryonline.com上托管的存储库。 However, I'm struggling to find a sane configuration. 但是,我很难找到一个理智的配置。 I'm inclined to suspect that there's something that I'm missing, but I'm at my wit's end, none of the documentation I've found seems to cover this use case in any detail, and I'm tired of going through the Artifactory plugin source code. 我倾向于怀疑有一些我缺少的东西,但是我的机智已经结束了,我发现的任何文档似乎都没有详细介绍这个用例,而且我已经厌倦了Artifactory插件源代码。 Any help at all is appreciated. 任何帮助都表示赞赏。

The scenario is the following. 场景如下。 I would like to: 我想要:

  1. build a free-style Jenkins project using SBT, independent of version number such that the current project version (as encoded in the pom/ivy artifacts) is implicit and automatic. 使用SBT构建一个自由风格的Jenkins项目,与版本号无关,这样当前项目版本(在pom / ivy工件中编码)是隐式和自动的。
  2. publish the artifacts and build info to an artifactory repository configured in Jenkins (not configured in the build.sbt in my SCM) 将工件和构建信息发布到Jenkins中配置的工件库(未在我的SCM中的build.sbt中配置)

Below are the approaches that I've tried. 以下是我尝试过的方法。

Approach 1: Free-style + Generic Artifactory Integration 方法1:自由式+通用的工件集成

First approach was to use a freestyle build, then use the Generic-Artifactory integration. 第一种方法是使用自由式构建,然后使用Generic-Artifactory集成。 For "Published Artifacts", I've set it to 对于“已发布的工件”,我已将其设置为

target/scala-2.11/*=>com.mycompany/my-module_2.11 目标/阶-2.11 / * => com.mycompany / MY-module_2.11

The build succeeds, the jar and sources-jar and javadoc-jar and ivy file and POM file are all generated in that directory. 构建成功,jar和sources-jar以及javadoc-jar和ivy文件以及POM文件都在该目录中生成。 However, the publish fails, 209 Conflict. 但是,发布失败,209冲突。 Artifactory log doesn't like the target path: Artifactory日志不喜欢目标路径:

Sending HTTP error code 409: The target deployment path 'com/mycompany/my-module_2.11/my-module_2.11-1.0.6.pom' does not match the POM's expected path prefix 'com/mycompany/my-module_2.11/1.0.6'. 发送HTTP错误代码409:目标部署路径'com / mycompany / my-module_2.11 / my-module_2.11-1.0.6.pom'与POM的预期路径前缀'com / mycompany / my-module_2不匹配。 11 / 1.0.6' 。 Please verify your POM content for correctness and make sure the source path is a valid Maven repository root path. 请验证您的POM内容是否正确,并确保源路径是有效的Maven存储库根路径。

I can make the 209 error go away, by not using the standard maven-2 pathing (which, among other things, requires disabling POM consistency checks for this repo), which suggests I'll have to update all downstream configuration to be able to work with this repo. 我可以通过不使用标准的maven-2路径(其中包括需要禁用此repo的POM一致性检查)来消除209错误,这表明我必须更新所有下游配置才能够与这个回购合作。

I can update the target path setting for the plugin to include the version number: 我可以更新插件的目标路径设置以包含版本号:

target/scala-2.11/*=>com.mycompany/my-module_2.11/1.0.6 目标/阶-2.11 / * => com.mycompany /我的-module_2.11 / 1.0.6

but that means I have modify my Jenkins build for every release, which seems to defeat the purpose. 但这意味着我已经为每个版本修改了我的Jenkins构建,这似乎打败了目的。 I can't imagine that's the proper way to use these tools. 我无法想象这是使用这些工具的正确方法。

Approach 2: Free-style + Artifactory Maven 方法2:自由式+ Artifactory Maven

In this case, I stuck with the free-style SBT build. 在这种情况下,我坚持使用自由式SBT构建。 Under "Build Environment", I selected "Maven3-Artifactory Integration". 在“构建环境”下,我选择了“Maven3-Artifactory Integration”。 I configured the plugin against my global artifactory repository, check "Deploy artifacts to Artifactory", and set the "Include Patterns" to 我针对我的全局工件存储库配置了插件,选中“将工件部署到Artifactory”,并将“包含模式”设置为

target/scala-2.11/* 目标/斯卡拉-2.11 / *

I ran a build, which generated the artifacts (including POM and ivy.xml files in the target/scala-2.11 directory), but nothing seemed to happen with respect to the deployment of artifacts. 我运行了一个构建,它生成了工件(包括目标/ scala-2.11目录中的POM和ivy.xml文件),但是在工件部署方面似乎没有发生任何事情。 There was nothing in the Artifactory log, no new builds, and nothing in the console output or Jenkins logs to indicate that it ever attempted to deploy any artifacts to my repository. Artifactory日志中没有任何内容,没有新的构建,控制台输出或Jenkins日志中没有任何内容表明它曾尝试将任何工件部署到我的存储库。

Approach 3: Free-style + Artifactory Ivy 方法3:自由式+ Artifactory常春藤

In this case, I stuck with the free-style build, but under "Build Environment", I selection the "Ant/Ivy-Artifactory Integration." 在这种情况下,我坚持使用自由式构建,但在“构建环境”下,我选择了“Ant / Ivy-Artifactory Integration”。 I selected my globally configured Artifactory repository, check "Publish artifacts to Artifactory" and "Use Maven Compatible Patterns". 我选择了全局配置的Artifactory存储库,选中“将工件发布到Artifactory”和“使用Maven兼容模式”。 I configured my SBT project to "publishLocal" (per the plugin instructions), and I set the following paths screenshot of ivy configuration . 我将我的SBT项目配置为“publishLocal”(根据插件说明),并设置了常春藤配置的以下路径截图 The project built and the artifacts were deployed to ~/.ivy2/local, but apparently there was no interception by the plugin and nothing was pushed to my configured Artifactory repo (maybe this plugin isn't compatible with free-style?) 构建项目并将工件部署到〜/ .ivy2 / local,但显然插件没有拦截,没有任何东西被推送到我配置的Artifactory仓库(也许这个插件与自由风格不兼容?)

I modified the SBT build to do "publish" instead of "publishLocal", hoping that the plugin would kick in and intercept the Ivy publish, but because my built.sbt isn't configured with a publishTo repository target, I naturally got an error that "Repository for publishing is not specified". 我修改了SBT构建来做“发布”而不是“publishLocal”,希望插件能够启动并拦截Ivy发布,但是因为我的built.sbt没有配置了publishTo存储库目标,所以我自然得到了一个错误“未指定用于发布的存储库”。

Approach 4: Dummy Maven build 方法4:虚拟Maven构建

Next approach: skip generic, go full maven. 下一步方法:跳过通用,转到完整的maven。 I setup a new build in Jenkins, a Maven project. 我在一个Maven项目Jenkins中设置了一个新版本。 It has a Pre-build step which runs my SBT build, generating the pom artifact along with the binary and source jars. 它有一个预构建步骤,它运行我的SBT构建,生成pom工件以及二进制和源jar。 I then configure the Build step to use the POM generated by my SBT build. 然后我配置Build步骤以使用由我的SBT构建生成的POM。 Unfortunately, the "Root POM" parameter of the jenkins/maven plugin doesn't accept a wildcard, so the only way I could get this to process was to specify the full (versioned) path: 不幸的是,jenkins / maven插件的“Root POM”参数不接受通配符,所以我能够处理它的唯一方法是指定完整(版本化)路径:

target/scala-2.11/my-resource_2.11-1.0.6.pom 目标/斯卡拉2.11 / MY-resource_2.11-1.0.6.pom

So, that's unfortunate and untenable, as far as I'm unwilling to update my Jenkins build everytime I increment version number. 所以,这是不幸的,也是站不住脚的,因为每次增加版本号时我都不愿意更新我的Jenkins构建版本。 Still, I wanted to see if this approach would work, so I pushed on. 不过,我想看看这种方法是否有效,所以我继续推进。 I added a post-build step of "Deploy Artifacts to Artifactory", against my globally configured Artifactory. 我在全局配置的Artifactory中添加了“将Artifacts部署到Artifactory”的构建后步骤。 With the maven goals "help:help", nothing was pushed, therefore there was nothing for the maven interceptor to intercept and push to my artifactory (that's my understanding as to how it works, anyway). 随着maven目标“帮助:帮助”,没有任何东西被推动,因此maven拦截器没有任何东西可以拦截并推动我的神器(这是我对它如何工作的理解,无论如何)。 So I tried again, replacing the maven goals in the Build step with "deploy". 所以我再次尝试,用“部署”替换Build步骤中的maven目标。 This time, the interceptor pushed up most (all?) of my dependencies to my Artifactory server. 这一次,拦截器将我的大多数(全部?)依赖项推送到我的Artifactory服务器。 However, after pushing all of the dependencies, it apparently failed trying to compile my "maven" project. 但是,在推送所有依赖项之后,它显然未能尝试编译我的“maven”项目。 I didn't look to much further into this, but I assume it is because the generated POM file doesn't specify any build instructions. 我没有进一步研究这个,但我认为这是因为生成的POM文件没有指定任何构建指令。

Conclusion 结论

Once again, any help is appreciated. 再一次,任何帮助表示赞赏。 It seems that this should be a fairly mainstream use case, and the documentation for the Artifactory plugin explicitly states that free-style build + Maven deploy is supported, but I'm obviously missing something. 看起来这应该是一个相当主流的用例,Artifactory插件的文档明确指出支持自由式build + Maven部署,但我显然缺少一些东西。 Any help is greatly appreciated! 任何帮助是极大的赞赏! Thank you. 谢谢。

That's a great question! 这是一个很好的问题!

Going with "Approach 1" is the way to go. 采用“方法1”是可行的方法。 If you don't want to include the version in the path, it makes the path non-maven compatible, which might be fine, but you need to configure the repo (as you know and did). 如果您不想在路径中包含该版本,它会使路径非maven兼容,这可能没问题,但您需要配置repo(如您所知和所做的那样)。 And yes, the solution in the comment is a valid trick as well. 是的,评论中的解决方案也是一个有效的技巧。

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

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