Jenkins管道并行邮政任务,以清除Docker容器
如果我在多个代理之间运行并行任务,而不是对每个作业执行后期操作,那么如何将其放在并行阶段本身?将它们全部放在每个阶段的问题是,如果该阶段与另一个阶段共享代理,则 docker system prune -f -a 可能会干扰其他阶段。
我试图确保构建代理上的缓存是清晰的,因此它总是从 Artifactory 中提取最新的内容。另外,在构建后进行清理,以确保没有任何东西悬空。
例如
stage("Docker stuff"){
parallel{
stage(foo){
agent{label "docker"}
steps{...}
}
stage(bar){
agent{label "docker"}
steps{...}
}
stage(foobar){
agent{label "docker"}
steps{...}
}
}
post{
always{
sh "docker image prune -f"
sh "docker volume prune -f"
sh "docker container prune -f"
sh "docker system prune -a -f"
sh "docker builder prune -a -f"
}
}
}
,上述问题是后操作仅在选择管理并行阶段的代理上运行,而不是在实际执行运行的代理上运行。
下面的问题是后期操作可能会干扰其他阶段。
stage("Docker stuff"){
parallel{
stage(foo){
agent{label "docker"}
steps{
script{
def dockerImage = _dockerImage("docker-local/foo-image")
docker.withRegistry( "https://artifactory-dev.company.com/", "svc_bar") {
dockerImage.push()
dockerImage.push("latest")
}
}
}
post{
always{
echo "========always========"
sh "docker image prune -f"
sh "docker volume prune -f"
sh "docker container prune -f"
sh "docker system prune -a -f"
sh "docker builder prune -a -f"
}
}
}
stage(bar){
agent{label "docker"}
steps{...}
post{...}
}
stage(foobar){
agent{label "docker"}
steps{...}
post{...}
}
}
}
If I'm running parallel tasks across multiple agents, instead of having a post action on each job, how can I have it on the parallel stage itself? The issue with having them all on each stage is that if the stage is sharing an agent with another stage, docker system prune -f -a can interfere with the other stage.
I am trying to ensure the cache is clear on the build agent, so it's always pulling the latest fresh from Artifactory. Plus cleaning up after the build to make sure nothing is left dangling.
For example
stage("Docker stuff"){
parallel{
stage(foo){
agent{label "docker"}
steps{...}
}
stage(bar){
agent{label "docker"}
steps{...}
}
stage(foobar){
agent{label "docker"}
steps{...}
}
}
post{
always{
sh "docker image prune -f"
sh "docker volume prune -f"
sh "docker container prune -f"
sh "docker system prune -a -f"
sh "docker builder prune -a -f"
}
}
}
The issue with the above is that the post actions run only on the agent selected to manage the parallel stages, not the agents actually doing the running.
The issue with the below is the post actions can interfere with other stages.
stage("Docker stuff"){
parallel{
stage(foo){
agent{label "docker"}
steps{
script{
def dockerImage = _dockerImage("docker-local/foo-image")
docker.withRegistry( "https://artifactory-dev.company.com/", "svc_bar") {
dockerImage.push()
dockerImage.push("latest")
}
}
}
post{
always{
echo "========always========"
sh "docker image prune -f"
sh "docker volume prune -f"
sh "docker container prune -f"
sh "docker system prune -a -f"
sh "docker builder prune -a -f"
}
}
}
stage(bar){
agent{label "docker"}
steps{...}
post{...}
}
stage(foobar){
agent{label "docker"}
steps{...}
post{...}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
邮政 {
总是 {
}
在我
看来,你不能同时在 docker 中执行某些操作,在不同的节点中我没有看到问题
post {
always {
}
}
It seems to me that you cannot perform certain actions in docker at the same time, in different nodes I do not see a problem