Jenkins - 如果构建失败,则部署上次成功构建的工件

时间:2017-03-15 16:57:36

标签: continuous-integration deployment continuous-delivery jenkins

如果当前的构建版本在任何时候失败,Jenkins是否可以部署上一次成功构建的工件?如果是这样的话?

我目前正在使用rsync从工作区部署我的文件,作为我的构建步骤之一。

我知道有一个名为BuildResultTrigger的插件我可以猜测我可以使用,但我不知道如何访问存档的工件并告诉我当前构建哪一个是最后一次成功的构建。

1 个答案:

答案 0 :(得分:3)

我建议在部署时,将已部署(已成功构建和测试)的版本复制到部署计算机上的某个位置。

然后,在Jenkins上运行测试时(假设您使用命令行启动测试):

ssh deploymentmachine rm -rf /where/you/store/them
ssh deploymentmachine cp -R /where/you/deploy/them /where/you/store/them
rsync -rvz /where/jenkins/built/the/files deploymentmachine:/where/you/deploy/them
ssh deploymentmachine sh runtests.sh || \
 (ssh deploymentmachine rm -rf /where/you/deploy/them; \
  ssh deploymentmachine cp -R /where/you/store/them /where/you/deploy/them; \
  ssh deploymentmachine rm -rf /where/you/store/them
  exit 1)
ssh deploymentmachine rm -rf /where/you/store/them

这应该会在失败时给出错误的退出状态并重新部署上一个成功的版本。

根据需要调整解决方案(例如,您可能以“sh runtests.sh”之外的其他方式启动测试,部署可能需要重新启动服务器而不是仅复制文件,并且目录路径需要调整)

相关问题