2

I setup a post action like in the examples:

pipeline {
    agent any
    stages {
        stage('Example1') {
            steps {
                bat 'return 1'                    
            }
        stage('Example2') {
            steps {
                echo 'Wont see this'
            }
        }
    }
    post { 
        always { 
            echo 'I will always say Hello'
        }
    }
}

So I do something in the first stage to make it fail. And I have a post action that always runs, but what happens when I run my pipeline in blueocean is it fails at the first stage and then just stops. Where do I see the post action that is always supposed to run??

red888
  • 27,709
  • 55
  • 204
  • 392

2 Answers2

1

Kind of late to the party but you have to use catchError before any steps that may fail. Something like this:

steps {
  catchError {
    bat 'return 1' 
  }             
}
real_kappa_guy
  • 313
  • 1
  • 4
  • 12
0

I hade a similar problem when I used agent none at the beginning of the pipeline. Try using a node in your post action:

post {
    always {
        node('master') {
            echo 'I will always say Hello'
        }
     }
}
Daniel Steinmann
  • 2,119
  • 2
  • 15
  • 25
  • Now I'm confused. Agent is descriptive node is scripted. So why does it have to be a scripted action and how does Jenkins treat it differently? – red888 Aug 16 '17 at 14:19
  • Good question, but I don't know the inner workings of Jenkins. I just noticed that specifying a `node` made my post action working. – Daniel Steinmann Aug 16 '17 at 14:34
  • 4
    If it's not working for you, why is it the accepted answer? – seeafish Feb 15 '18 at 11:33