Reputation: 539
Possible to send an email if a Jenkins 'Build Passes' after a Build Failure?
Is it then possible to send email to say that the build has passed
Upvotes: 1
Views: 1521
Reputation: 2682
You can achieve it by using shell script in Jenkins.
CURRENT_BUILD_STATUS=$(curl --silent ${BUILD_URL}api/json | jq -r '.result')
prevBuildNo=$(($BUILD_NUMBER-1))
echo $prevBuildNo
PREVIOUS_BUILD_STATUS=$(curl -- silent http://jenkins.org.com/jenkins/job/job/jobname/${prevBuildNo}/api/json | jq -r '.result)
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