[JIRA] (JENKINS-36765) Pipeline: Send notification "Back to normal" state

10 views
Skip to first unread message

crummynz@gmail.com (JIRA)

unread,
Jul 18, 2016, 10:49:01 AM7/18/16
to jenkinsc...@googlegroups.com
malcolm crum created an issue
 
Jenkins / Improvement JENKINS-36765
Pipeline: Send notification "Back to normal" state
Issue Type: Improvement Improvement
Assignee: Kurt Madel
Components: slack-plugin
Created: 2016/Jul/18 2:48 PM
Labels: pipeline slack
Priority: Minor Minor
Reporter: malcolm crum

I understand how to send slack notifications in a Pipeline script on success, or on failure. This is useful for build jobs.

For automated tests, a notification on each job is not so useful. Instead, I'd rather be notified when a job fails, or when a job succeeds and the previous job failed. Pre-Pipeline, this was referred to as "Back to normal" I think.

I'd like a way to know that a previous build failed. Something like this:

[... test completed successfully]
if (previousBuild.success() == false) {
   [send slack message: "Test back to normal]
}
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

martin.sander@sap.com (JIRA)

unread,
Feb 3, 2017, 8:03:01 AM2/3/17
to jenkinsc...@googlegroups.com
Martin Sander commented on Improvement JENKINS-36765
 
Re: Pipeline: Send notification "Back to normal" state
def previousResult = currentBuild.previousBuild?.result
if (previousResult && previousResult != currentBuild.result) {
    // do it
}

iviktorin@fit.vutbr.cz (JIRA)

unread,
Mar 23, 2017, 8:55:02 AM3/23/17
to jenkinsc...@googlegroups.com

Hello,

this code:

pipeline {
...
}
post {
        success {
            def previousResult = currentBuild.previousBuild?.result
            if (previousResult && previousResult != currentBuild.result) {
                emailext attachLog: true, to: "${env.MAINTAINERS}", subject: "Fixed: ${env.JOB_NAME} #${currentBuild.number}",
                    body: "See ${env.BUILD_URL} for details."
            }
        }
}

produces:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 44: Expected a step @ line 44, column 13.
               def previousResult = currentBuild.previousBuild?.result
               ^

WorkflowScript: 45: Expected a step @ line 45, column 13.
               
if (previousResult && previousResult != currentBuild.result) {
 
                                                            

 

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

martin.sander@sap.com (JIRA)

unread,
Mar 24, 2017, 11:21:01 AM3/24/17
to jenkinsc...@googlegroups.com

Jan Viktorin:

The attached code snippet is for the Pipeline Plugin, see e.g. https://jenkins.io/solutions/pipeline/.

Your snippet seems to be using the "declarative pipeline" from the Pipeline Model Definition Plugin, which is not the same. The latter is supposed to be easier to use, but less powerful.

martin.sander@sap.com (JIRA)

unread,
Mar 24, 2017, 11:22:02 AM3/24/17
to jenkinsc...@googlegroups.com
Martin Sander edited a comment on Improvement JENKINS-36765
[~jviki]:

The attached code snippet is for the [Pipeline Plugin|https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin], see e.g. https://jenkins.io/solutions/pipeline/.

Your snippet seems to be using the "declarative pipeline" from the [Pipeline Model Definition Plugin|https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Model+Definition+Plugin], which is not the same. The latter is supposed to be easier to use, but less powerful.


Maybe you are looking for https://jenkins.io/blog/2017/02/15/declarative-notifications/.

inflatedwizard@gmail.com (JIRA)

unread,
Sep 6, 2018, 12:23:03 PM9/6/18
to jenkinsc...@googlegroups.com

So the "Pipeline Plugin" link in your post times out. In jenkins by default, when I select "New Item" -> "Pipeline", then using the syntax above does not work. Not sure if the pipeline syntax changes for the default pipeline project type depending on what you have installed, however I found that the syntax above does not work for me either, and in my perspective, it is not setup properly.

Here is the proper layout that allows my pipeline to function properly for build back to normal:

pipeline {
   environment {
     def previousResult = '${currentBuild.previousBuild?.result}'
   }

   // pipeline stages/steps
   post {
     success {
       script { // wrap the if statement in a script tag.


         if (previousResult && previousResult != currentBuild.result)

{            // do it          }

       }
     }

}

This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

inflatedwizard@gmail.com (JIRA)

unread,
Sep 6, 2018, 12:32:02 PM9/6/18
to jenkinsc...@googlegroups.com
Jeff Jenkins edited a comment on Improvement JENKINS-36765
So the "Pipeline Plugin" link in your post times out. In jenkins by default, when I select "New Item" -> "Pipeline", then using the syntax above does not work. Not sure if the pipeline syntax changes for the default pipeline project type depending on what you have installed, however I found that the syntax above does not work for me either, and in my perspective, it is not setup properly.

Here is the proper layout that allows my pipeline to function properly for build back to normal:

pipeline {
   environment {
  
   def previousResult = '${currentBuild.previousBuild?.result}'
   }

  
// pipeline stages/steps
   post {
     success {
       script { // wrap the if statement in a script tag.

         def previousResult = currentBuild.previousBuild?.result
        
if (previousResult && previousResult != currentBuild.result) {

           \{            // do it
         }

       }
     }

}

timjacomb1@gmail.com (JIRA)

unread,
Dec 1, 2019, 2:15:08 PM12/1/19
to jenkinsc...@googlegroups.com
Change By: Tim Jacomb
Status: Open Fixed but Unreleased
Resolution: Fixed
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

timjacomb1@gmail.com (JIRA)

unread,
Dec 1, 2019, 2:15:08 PM12/1/19
to jenkinsc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages