Before Pipeline, I used Email-ext plugin to define triggers for sending emails (on first failure, and when back to success).
But in the Pipeline version, I can't control the triggers, I can only "send always", or send based on current build result.
How do I send emails in pipeline based on more general triggers? (first failure, first success, etc)
Thanks!
While setting up jenkins pipeline, you have a Pipeline Syntax
link below the Groovy Script Editor like in the picture below.
Clicking on the link takes you to snippet generator like in the picture below.
Here I've selected emailext : Extended plugin option. You can select simple mail option from the dropdown as well and generate the snippet.
To determine the build status of the current job Jenkins provides the environmental variables which you can use while writing your groovy script. You can find the list of global environment variables by clicking the link provided at the end of Snippet Generator page.
Below is the list of properties of currentBuild
environment variable for your reference.
The currentBuild
variable may be used to refer to the currently running build.
It has the following readable properties:
number
result
SUCCESS
, UNSTABLE
, or FAILURE
(may be null for an ongoing build)currentResult
SUCCESS
, UNSTABLE
, or FAILURE
. Will never be null.resultIsBetterOrEqualTo(String)
SUCCESS
, UNSTABLE
, or FAILURE
) and returns true if the current build result is better than or equal to the provided result.resultIsWorseOrEqualTo(String)
SUCCESS
, UNSTABLE
, or FAILURE
) and returns true if the current build result is worse than or equal to the provided result.displayName
#123
but sometimes set to, e.g., an SCM commit identifierdescription
id
number
as a stringtimeInMillis
startTimeInMillis
duration
durationString
previousBuild
nextBuild
absoluteUrl
buildVariables
env
changeSets
kind
and is a list of commits; each commit has a commitId
, timestamp
, msg
, author
, and affectedFiles
each of which has an editType
and path
; the value will not generally be Serializable
so you may only access it inside a method marked @NonCPS
rawBuild
hudson.model.Run
with further APIs, only for trusted libraries or administrator-approved scripts outside the sandbox; the value will not be Serializable
so you may only access it inside a method marked @NonCPS
result
displayName
description
Hope this helps. Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With