laters
V2EX  ›  DevOps

jenkins pipeline 如何在 stage3 错误的时候,返回 stage2 重新执行

  •  
  •   laters · Mar 30, 2023 · 2327 views
    This topic created in 1153 days ago, the information mentioned may be changed or developed.
    stages {
                    stage('1') {
                        steps {
                        }
                    }
                    stage('2') {
                        steps {
                        }
                    }
                    stage('3') {
                        steps {
                            script{
                                try{}catch{
                                	// 重新回到 stage2 执行构建
                                }
                            }
                        }
                    }
                }
            }
    

    这样是否能做到

    3 replies    2023-04-01 09:23:46 +08:00
    Aliencn
        1
    Aliencn  
       Mar 30, 2023
    大概想到两个方法。
    1.把要做的 stage2 里的内容写成函数,stage3 里判断失败调用函数。
    2 把 stage2 和 stage3 拆成多个 Job ,stage3 执行成功和执行失败调用不同的 Job 来执行下面的内容。
    laters
        2
    laters  
    OP
       Mar 30, 2023
    @Aliencn 好的,谢谢
    julyclyde
        3
    julyclyde  
       Apr 1, 2023
    这个需求可能有问题啊

    如果你想通过重新运行上一个步骤的方法来修复,那为什么当时运行的时候不一次做好呢?
    说明目前的写法里,上一个步骤有可能存在隐性的外部依赖
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3190 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 12:35 · PVG 20:35 · LAX 05:35 · JFK 08:35
    ♥ Do have faith in what you're doing.