xGIx
xGIx

Reputation: 539

Possible to send an email if a Jenkins 'Build Passes' after a Build Failure?

Possible to send an email if a Jenkins 'Build Passes' after a Build Failure?

  1. For example I have x3 builds that fail
  2. But the fourth build passes

Is it then possible to send email to say that the build has passed

Upvotes: 1

Views: 1521

Answers (1)

ANIL
ANIL

Reputation: 2682

You can achieve it by using shell script in Jenkins.

Get current build status

CURRENT_BUILD_STATUS=$(curl --silent ${BUILD_URL}api/json | jq -r '.result')

Get previous build number

prevBuildNo=$(($BUILD_NUMBER-1))

echo $prevBuildNo

Get previous build status

PREVIOUS_BUILD_STATUS=$(curl -- silent http://jenkins.org.com/jenkins/job/job/jobname/${prevBuildNo}/api/json | jq -r '.result)

Cheking if the previous build was failed and the current build is successful

if ["$CURRENT_BUILD_STATUS" = "SUCCESS"] && ["$PREVIOUS_BUILD_STATUS" = "FAILED"] then #sending the mail echo $ echo "hello world" | mail -s "a subject" [email protected] else echo "No e-mail trigger as the previous build was successful." fi

Upvotes: 0

Related Questions