【问题标题】:Jenkins: Execute shell script at end of job regardless of result詹金斯:无论结果如何,在作业结束时执行shell脚本
【发布时间】:2020-09-10 10:33:59
【问题描述】:

我想在 Jenkins 作业结束时运行 HTTP POST 请求,无论它是失败还是提前中止。我打算用一个简单的 Curl 命令来做这个。

我知道Post build task plugin 可以做到这一点。 但是,我相信,它将整个控制台保存到 RAM 中以进行文本比较,这不仅我不需要,而且很可能会导致我们的 master 出现 OOM 异常。

另外,我没有看到任何关于 plubin 的文档,可以尝试仅在 UI 中使用 Jenkins 脚本进行测试。 有没有人有任何替代方法或方法可以在 Jenkins 文件中调用 postbuild-task

【问题讨论】:

    标签: jenkins jenkins-plugins


    【解决方案1】:

    您可以使用后期构建步骤。添加此帖子部分

    pipeline {
      agent any
      stages {
        stage(""){
          steps {
            script {
        
            }
          }
        }
      }
      post { #---------------This block
        always {
          script {
            your stuff which you want execute no matter what
          }
        }
      }
     }
    

    【讨论】:

      【解决方案2】:

      由于我的原始代码没有使用詹金斯管道

      【讨论】:

        【解决方案3】:

        你可以在阶段之后添加一个帖子块

        post {
            success {
              //Success block
            }
        
            unstable {
              //unstable block
            }
        
            failure {
              //Failure block
            }
        
            always {
              //This block will always be executed regardless of the build outcome
              echo "Build completed with status: ${currentBuild.result}"
            }
        }
        

        标准流示例:

        pipeline {
            agent any
            stages {
                stage("1") {
                    }
                stage("2") {
                    }
                 ....
               }
          post {
            always {
                   //This block will always be executed
                   }
               }
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多