Dinho
Dinho

Reputation: 43

Running a script post successful build in jenkins

I am trying to run a bash script after a successful build in jenkins.

stages {
  stage("test") {
    steps {
      ...
    }
    post {
      success {
        steps {
          sh "./myscript"
        }
      }
    }
  }
}

I am getting an error saying that method "steps" does not exist. How can I run a script after a successful build?

Upvotes: 0

Views: 2131

Answers (1)

chenchuk
chenchuk

Reputation: 5742

You need to remove the ”steps” inside the ”success” block. call the script directly inside the ”success” block.

according to the docs which is quite confusing, the ”success” is a container for steps (so no need to add another nested ”steps” ):

https://jenkins.io/doc/book/pipeline/syntax/#post

stages {
  stage("test") {
    steps {
      ...
    }
    post {
      success {
        sh "./myscript"
      }
    }
  }
}

Upvotes: 2

Related Questions