我怎样才能让Hudson自动构建&安装发布工件,而不仅仅是快照?

发布于 2024-09-28 01:17:32 字数 1388 浏览 7 评论 0原文

我正在我的笔记本电脑上开发几个成熟的项目,并定期推送到 github。我已经在云中设置了一个私有 hudson 服务器,该服务器轮询 git 存储库以获取更新,从而执行构建 - 到目前为止一切顺利。

不幸的是,当我在笔记本电脑上执行“mvn release:prepare”以执行发布(例如“1.5”)时,发生的两个提交(将 1.5-SNAPSHOT 更改为 1.5,然后将 1.5 更改为 1.6-SNAPSHOT)被一起推送到我的 git repo - Hudson 显然构建了最新的版本,即 1.6-SNAPSHOT - 并且完全忽略了 1.5 版本。

这并不重要,但项目相互依赖,我想在我的 poms 中声明非快照版本。然而,当项目 B 依赖于项目 A 的 1.5 版本时,在 Hudson 盒子上的 hudson 用户的本地 maven 存储库中找不到它 - 因为它从未被构建过 - 因此项目 B 的构建失败。

如果我能让 Hudson 变得更聪明,并且当它看到 Maven 发布版本飞过时,会强制构建并安装该特定版本,然后再继续构建稍后的快照提交,那就太好了。

我一直在研究 Hudson 插件,特别是“M2 发布插件”:

http://wiki.hudson-ci.org//display/HUDSON/M2+Release+Plugin

-但是,该插件似乎更适合手动选择您想要升级的版本到一些更官方的 Maven Repo,而不是强迫 Hudson 自动构建和构建。安装它遇到的每个版本。

更新:我的一些基本需求让我重新思考我想要实现的目标 - 很抱歉没有早点表达它们:

  • 大多数项目都是开源的或打算最终开放,并且我希望任何人都能够 git 克隆 任何单个项目,签出发布标签,并执行 mvn install ,而不需要除 Maven Central 之外的任何其他依赖项存储库。
  • 为了获得一致的结果(在我的笔记本电脑、hudson 服务器和其他人的结帐中),这显然表明我倾向于在我的 poms 中声明非快照依赖项(至少对于发布版本)。
  • 这引导我尝试让 Hudson 在发布工件呼啸而过时对其进行“mvn 安装”,这样以后,Hudson 构建项目 B 时就不会在找不到项目 A 的发布版本时失败(这就是项目 A 的发布版本)这个问题来自)

另外:

  • 我使用 sonotype 出色的 oss 托管,这需要 GPG 签名 - 而且我不想将我的 GPG 密钥存储在任何我无法握在手中的硬件上:) - 所以把它塞在上面云中的 Hudson 服务器不是一个选择。
  • 从心理上来说,让 Hudson 服务器进行发布对我来说有点陌生 - 我真的只是想将它用于 CI。

I'm developing several mavenised projects on my laptop, and periodically pushing to github. I've set up a private hudson server in the cloud that polls the git repositories for updates, and thus performs builds - so far so good.

Unfortunately, when I execute a 'mvn release:prepare' on my laptop to perform a release (say '1.5'), the two commits that occur (changing 1.5-SNAPSHOT to 1.5, then 1.5 to 1.6-SNAPSHOT) are pushed together into my git repo - and Hudson obviously builds the most recent one, ie 1.6-SNAPSHOT - and completely ignores the 1.5 release.

It wouldn't matter so much, but the projects depend on each other, and I would like to declare non-snapshot versions in my poms. However, when project B depends on version 1.5 of project A, it's nowhere to be found in the local maven repository for the hudson user on the Hudson box - because it's never been built - and so the build of project B fails.

It would great if I could make Hudson a little cleverer, and when it sees a maven release version flying through, forces a build and install of that particular version, before proceeding to do a build of the later snapshot commit.

I've been looking through the Hudson plugins, and in particular the 'M2 Release Plugin':

http://wiki.hudson-ci.org//display/HUDSON/M2+Release+Plugin

-however, that plugin seems to be more geared towards manually selecting a build you want to promote up to some more official Maven Repo, rather than forcing Hudson to automatically build & install every release build it comes across.

Update: some of my underlying requirements have led me to rethink what I want to achieve here- apologies for not expressing them earlier:

  • Most of the projects are open-source or intended to be open eventually, and I would like anyone to be able to git clone any single project, checkout a release tag, and do a mvn install without requiring any other repo for dependencies but maven central.
  • In order to get consistent results (across my laptop, the hudson server, and other people's checkouts), this obviously indicates a preference for declaring non-snapshot dependencies in my poms (at least for the release versions).
  • This led me down the path of trying to get Hudson to 'mvn install' the release artifacts as they whizzed past, so that later, Hudson building project B wouldn't fail when it couldn't find project A's release version (which is where this question came from)

Additionally:

  • I use sonotype's wonderful oss hosting, which requires GPG signing - and I don't want to have my GPG key stored on any hardware I can't hold in my hand :) - so bunging it up on the Hudson server in the cloud is not an option.
  • Mentally, having the Hudson server do releases is a bit foreign to me - I really just want it for CI.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

指尖凝香 2024-10-05 01:17:32

您现在需要的是实际执行发布。引用 Maven - 使用发布插件指南

执行发布

该插件将提取文件修订版本
与当前版本相关。
Maven会编译、测试和打包
将版本化的项目源代码放入
一件神器。 最终交付成果
然后将被释放到
适当的 Maven 存储库

release:perform 目标将:

  1. 提取新标签名称下的文件修订版本。
  2. 在提取的实例上执行 Maven 构建生命周期
    项目。
  3. 将版本化工件部署到适当的本地和远程
    存储库

参考资料

What you need now is to actually perform the release. Quoting the Maven - Guide to using the release plugin:

Performing the release

The plugin will extract file revisions
associated with the current release.
Maven will compile, test and package
the versioned project source code into
an artifact. The final deliverable
will then be released into an
appropriate maven repository
.

The release:perform goal will:

  1. Extract file revisions versioned under the new tag name.
  2. Execute the maven build lifecycle on the extracted instance of the
    project.
  3. Deploy the versioned artifacts to appropriate local and remote
    repositories
    .

References

别在捏我脸啦 2024-10-05 01:17:32

您可以指定配置文件来确定构建是在本地还是远程部署:

<project>
    <profile>
        <id>local-deploy</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <distributionManagement>
            <repository>
                <id>local-repo</id>
                <name>My Local Repo</name>
                <url>file://my/local/repo/dir</url>
            </repository>
        </distributionManagement>
    </profile>
    <profile>
        <id>remote-deploy</id>
        <activation>
            <activeByDefault>false</activeByDefault>
            <property>
                <name>remote.repo.url</name>    
            </property>
        </activation>

        <distributionManagement>
            <repository>
                <id>remote-repo</id>
                <name>My Remote Repo</name>
                <url>${remote.repo.url}</url>
            </repository>
        </distributionManagement>
    </profile>
</project>

然后您可以安全地运行 release:perform 目标,并且通过传入remote.repo.url 的值,您还可以可以选择远程部署。

You could specify profiles that determine whether the build is to be deployed locally or remotely:

<project>
    <profile>
        <id>local-deploy</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <distributionManagement>
            <repository>
                <id>local-repo</id>
                <name>My Local Repo</name>
                <url>file://my/local/repo/dir</url>
            </repository>
        </distributionManagement>
    </profile>
    <profile>
        <id>remote-deploy</id>
        <activation>
            <activeByDefault>false</activeByDefault>
            <property>
                <name>remote.repo.url</name>    
            </property>
        </activation>

        <distributionManagement>
            <repository>
                <id>remote-repo</id>
                <name>My Remote Repo</name>
                <url>${remote.repo.url}</url>
            </repository>
        </distributionManagement>
    </profile>
</project>

Then you can safely run the release:perform goal and, by passing in a value for remote.repo.url, you also have the option of a remote deploy.

匿名的好友 2024-10-05 01:17:32

我更新了我的问题描述,提及我在 poms 中声明非快照依赖项的偏好(至少对于发布版本),以便获得一致的结果(在我的笔记本电脑、hudson 服务器和其他人的结帐中)-我真的希望其他人能够检查我的代码,并以零的方式开始寻找不可知的快照依赖项。

它想要在我的依赖项中使用非快照版本,这导致了这个问题 - Hudson 的正常行为并没有使使用“发布”版本变得容易,至少不需要等待依赖项的发布版本循环到 Maven 中心。

然而,我决定,如果我想忠实于我的基本要求 - 人们可以轻松地签出并构建我的代码 - 那么这就是我必须做的:即等待 Maven Central 同步。

我只想在发布版本中坚持这一点(否则我永远不会完成任何事情!),因此我会很乐意使用快照依赖进行开发 - 直到我真正做的事情为止 想要发布一个版本,此时我希望所有 deps 都可以在 Maven Central 中正确使用。

直到最近我才知道有任何方法可以强制执行此操作,但更多的谷歌搜索发现了“enforcer”插件:

http://maven.apache.org/enforcer/enforcer-rules/requireReleaseDeps.html

- 将 'onlyWhenRelease' 标志设置为 true,看起来它应该完美地强制执行什么我想做。

在回答我原来的标题问题(“我怎样才能让 Hudson 自动构建和安装发布工件,而不仅仅是快照?”),我的答案是:

  1. 似乎没有完全微不足道的方法让 Hudson 做到这一点(没有Hudson 的副作用还尝试在其检测到的每次签入时执行“发布”,这可能需要额外的“配置文件”配置来停止发布的实际正常操作,例如 GPG 签名)
  2. 不要这样做。

I've updated my problem description to mention my preference for declaring non-snapshot dependencies in my poms (at least for the release versions), in order to get consistent results (across my laptop, the hudson server, and other people's checkouts) - I really want other people to be able to check out my code and get going with zero mucking about looking for unknowable snapshot dependencies.

It was wanting to use non-snapshot versions in my dependencies that led to this question- Hudson's normal behaviour didn't make using 'release' versions easy, at least without waiting for the release version of the dependency to cycle thru to maven central.

However, I've decided that if I want to be true to my underlying requirement - that people can easily checkout and build my code - then that is what I have to do: i.e. wait for maven central to sync up.

I only want to hold myself to this for release builds (otherwise I'd never get anything done!), and so will happily develop using snapshot deps - up until the point where I actually do want to make a version release, at which point I want all the deps to be properly available in maven central.

I wasn't aware of any way to enforce this until recently, but a bit more googling found me the 'enforcer' plugin:

http://maven.apache.org/enforcer/enforcer-rules/requireReleaseDeps.html

-with the 'onlyWhenRelease' flag set to true, it looks like it should perfectly enforce what I want to do.

In answer to my original headline question then ('How can I make Hudson automatically build & install release artifacts, rather than just snapshots?'), my answer is:

  1. There appears to be no completely trivial way of making Hudson do this (without the side-effect of Hudson also attempting to do a 'release' with every checkin it detects, which can require additional 'profile' configuration to stop the actual normal actions of a release, eg GPG signing)
  2. Don't do that.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文