在步骤之间找不到这样的DSL方法“步骤”

时间:2019-09-02 06:04:40

标签: continuous-integration jenkins-pipeline jenkins-groovy

每当CI使用groovy脚本失败时,我都会尝试发布到松弛频道。但是,当我尝试在内部故障块中实现此操作时,却出现了此错误

Error when executing failure post condition:
java.lang.NoSuchMethodError: No such DSL method 'steps' found among steps [archive, bat, build, catchError, checkout, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, echo, envVarsForTool, error, fileExists, getContext, git, input, isUnix, junit, library, libraryResource, load, lock, mail, milestone, node, parallel

但是,我能够应用相同的代码在stage块下的其他管道中发送松弛通知。应用于post block时似乎出现了问题。

post {
      always {
        cleanWs()
      }
      failure {
        steps {
          slackSend baseUrl: 'https://hooks.slack.com/services/',
          channel: '#build-failures',
          iconEmoji: '',
          message: "CI failing for - #${env.BRANCH_NAME} - ${currentBuild.currentResult}  (<${env.BUILD_URL}|Open>)",
          teamDomain: 'differentau',
          tokenCredentialId: 'slack-token-build-failures',
          username: ''
        }
      }
    }

在此方面的任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

这应该有效:

post {
      always {
        cleanWs()
      }
      failure {
          slackSend baseUrl: 'https://hooks.slack.com/services/',
          channel: '#build-failures',
          iconEmoji: '',
          message: "CI failing for - #${env.BRANCH_NAME} - ${currentBuild.currentResult}  (<${env.BUILD_URL}|Open>)",
          teamDomain: 'differentau',
          tokenCredentialId: 'slack-token-build-failures',
          username: ''
        }
    }