Below is my Jenkins pipeline script. I wish to call ex("ansible-failed") 
function whenever the ansible-playbook test.yml fails and thereby abort the 
pipeline. Below is my pipeline script.


def ex(param)
    {    echo "ABORT due to:" + param    }

pipeline    {
    stages        {
        stage('first')  {
             steps         {
                script       {
                    def user = "user1"
                    }

                echo "Calling ansible"

                ansiblePlaybook(playbook: '/app/test.yml' extraVars: [ 
app_ip: "10.0.0.12,10.0.0.13" ])

                }
            }
        stage('second')   {
                 steps     {
                  script     {
                    println "Second Play"
                    }
                }
            }

        }
    }



The above Jenkins pipeline script invokes ansible-playbook however, I do 
not know how to detect if the ansible play succeeded or failed. In case it 
failed I wish to call the ex() function and abort the Jenkins pipeline.


Incase ansible-playbook run succeeds then I wish to simply continue and 
execute stage('second').


Can you please suggest how we can check the condition if ansible run 
succeeded or failed inside the Jenkins pipeline script?

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/9fb5ac3c-ba86-4453-9b98-3ed3f008a14e%40googlegroups.com.

Reply via email to