首页 > 解决方案 > 将构建后的 shell 脚本添加到 Groovy 作业执行器

问题描述

我有一个看起来像这样的脚本:

cronjobs.groovy:

job('MYJOB') {

  triggers {
    cron('H * ** *')
  }

  steps {
    shell('some shell script')
    shell('some othre shell')
  }
}

我想在 MYJOB 执行失败时添加另一个 shell 以在此处运行。是否可以?还是我必须实施管道?我可以以这种方式实现吗?我需要任何插件吗?

job('MYJOB') {

  triggers {
    cron('H * ** *')
  }

  steps {
    shell('some shell script')
    shell('some other shell script')
  }

  post {
    failure {
      shell('some shell script')
      shell('some more shell script')
    }
}

标签: jenkinscronjenkins-groovyjenkins-job-dsl

解决方案


那么根据job dsl docs,job使用publishers指令进行后期构建操作,但是你不能指定失败条件,也不能直接执行shell命令,尽管你可以调用一个groovy脚本

所以最好改用管道


推荐阅读