You could something like the following, where if all actions have worked, 
it'll simply read the slack action and perform it.

stage ("Publish CF app") {
         environment {
            JENKINSBOT = credentials('...')
         }
         
         when {
            branch "develop"
         }
         
         steps {
            script {
               STAGE_NAME = "Publish CF app"
            }
            
            // Login and push
            sh "cf api ..."
            sh "cf login ... -u $JENKINSBOT_USR -p $JENKINSBOT_PSW"
            sh "cf push"
      
            slackSend (
               color: '#199515',
               message: "$JOB_NAME: <$BUILD_URL|Build #$BUILD_NUMBER> 
passed successfully."
            )
         }
      }

You could also use the POST directive inside a stage:

stage {
   steps {
   ...
   }
 
   post {
       success {
           slack...
       }
       failure {
           slack...
       }
    }
}

Now, once a stage fails, the whole job fails, so you don't really need to 
handle the failure in each stage. Instead you can also use POST globally:
And as you can see in my first example, I basically set a "STAGE_NAME" in 
each stage and use it in the failure directive globally

stages {
    stage {
        steps {
        
        }
    }


    stage {
        steps {
        
        }
    }


    post {
        success {
        
        }
        failure {
            slackSend (
            color: '#F01717',
            message: "$JOB_NAME: <$BUILD_URL|Build #$BUILD_NUMBER>, 
'$STAGE_NAME' stage failed."
         )
        }
    }
}



On Friday, April 7, 2017 at 1:41:29 PM UTC+3, Per Ostman wrote:
>
> Hi!
>
> I'm trying to figure out how to get hold of the result of a stage in a 
> pipeline job to report progress/status in e g slack as the pipeline stages 
> execute.
>
> Does anyone have any pointers to how to accomplish this?
>
> /P
>

-- 
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/0c9ade5c-4541-4711-bd49-7cd5f8add805%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to