Hi Shifa,

I don't know if function ansiblePlaybook returns output or not. But, you 
can write the result of ansiblePlaybook in some text file.
After completion of ansiblePlabook function, checks the status of the 
result from a text file.

save the result as some variable "retVal".

then in between two-stages execute following command

stage('stg_1'){}

if( retVal == 'Fail') {

   ex()

   currentBuild.result = 'ABORTED'

   return}

stage('stg_2'){}


On Wednesday, 1 April 2020 07:02:53 UTC+2, Shifa Shaikh wrote:
>
> 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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/37ad0bd5-50d6-4f38-86f3-633687bc3772%40googlegroups.com.

Reply via email to