如何在詹金斯(Jenkins)中确保相同的git checkout用于构建和部署作业? [英] How to ensure same git checkout for build and deploy jobs in Jenkins?

查看:330
本文介绍了如何在詹金斯(Jenkins)中确保相同的git checkout用于构建和部署作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Jenkins中,我有一个构建"作业设置来轮询我的git repo并自动基于更改进行构建.然后,我有单独的部署到DEV",部署到QA"等作业,这些作业将调用适当部署的Ant构建.目前,此配置的效果很好.

In Jenkins, I have a "Build" job setup to poll my git repo and automatically build on change. Then, I have separate "Deploy to DEV", "Deploy to QA", etc. jobs that will call an Ant build that deploys appropriately. Currently, this configuration works great.

但是,此过程有利于在最新的开发分支上部署最新的构建.我使用Copy Artifact插件允许用户选择要部署的版本.此外,用于构建/部署的Ant脚本是回购协议的一部分,并且可能会发生更改.这意味着工件在两个版本之间可能不兼容.因此,理想的是,我确保使用相同的git checkout运行构建和部署作业.

However, this process favors deploying the latest build on the latest development branch. I use the Copy Artifact plugin to allow the user to choose which build to deploy. Also, the Ant scripts for build/deploy are part of the repo and are subject to change. This means it's possible the artifact could be incompatible between versions. So, it's ideal that I ensure that the build and deploy jobs are run using the same git checkout.

有没有更简单的方法? Deploy作业应该可能会从选定的构建和签出中获得git签出哈希.但是,我看不到有执行此操作的任何选项或插件.

Is there an easier way? It ought to be possible for the Deploy job to obtain the git checkout hash used from the selected build and checkout. However, I don't see any options or plugins that do this.

关于如何简化此配置的任何想法?

Any ideas on how to simplify this configuration?

推荐答案

对于Git存储库,详细信息会有所不同(请参见 https://stackoverflow.com/a/13117975/466874 ),但是对于基于SVN的作业,我们要做的是在以下位置进行构建作业(重新)创建SVN标签(静态名称如"LatestSuccessfulBuild")成功完成后,我们将部署作业配置为使用该标记作为其回购URL,而不是中继线位置.这样可以确保部署始终是构建作业成功构建的任何版本(意味着已通过所有单元测试,等等),而不是允许新的干线提交潜入部署构建中.

The details would vary for a Git repo (see https://stackoverflow.com/a/13117975/466874), but for our SVN-based jobs, what we do is have the build job (re)create an SVN tag (with a static name like "LatestSuccessfulBuild") at successful completion, and then we configure the deployment jobs to use that tag as their repo URL rather than the trunk location. This ensures that deployments are always of whatever revision was successfully built by the build job (meaning all unit tests passed, etc.) rather than allowing newer trunk commits to sneak into the deployment build.

这篇关于如何在詹金斯(Jenkins)中确保相同的git checkout用于构建和部署作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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