Jenkins - 如果构建失败部署上次成功构建的工件
Jenkins - If a build fails deploy the artifacts of the last successful build
如果当前构建在任何时候失败,Jenkins 是否可以部署上次成功构建的工件?如果有怎么办?
作为我的构建步骤之一,我目前正在使用 rsync 从工作区部署我的文件。
我知道有一个名为 BuildResultTrigger
的插件,我猜我可以使用它,但我不知道如何访问存档的工件并告诉我当前的构建是最后一个成功的构建。
我建议在部署时,将已部署(已成功构建和测试)的版本复制到部署机器上的某个位置。
然后,当 运行 对 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" 的其他方式开始测试,部署可能需要重新启动服务器而不是仅仅复制文件,并且目录路径需要调整).
如果当前构建在任何时候失败,Jenkins 是否可以部署上次成功构建的工件?如果有怎么办?
作为我的构建步骤之一,我目前正在使用 rsync 从工作区部署我的文件。
我知道有一个名为 BuildResultTrigger
的插件,我猜我可以使用它,但我不知道如何访问存档的工件并告诉我当前的构建是最后一个成功的构建。
我建议在部署时,将已部署(已成功构建和测试)的版本复制到部署机器上的某个位置。
然后,当 运行 对 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" 的其他方式开始测试,部署可能需要重新启动服务器而不是仅仅复制文件,并且目录路径需要调整).