Jenkins: Sending email based on each build step result in same Jenkins Job

后端 未结 2 1300
孤独总比滥情好
孤独总比滥情好 2021-01-13 18:44

I am just wondering how to send out email with Email-ext plugin based on each build step result on same Jenkins Job. Here is my scenario

My Jenkins job has 3 Build s

相关标签:
2条回答
  • 2021-01-13 19:11

    Instead of customizing email ext consider breaking up job into 2 jobs:

    • job 1 builds and has this post build configuration
      • Build Other Projects with Trigger only if build succeeds checked
      • Configure email-ext to only send mail in case of failure
    • job 2 runs test and sends mail

    For both jobs set job parameters in (job)/Configure/Advanced Project Options to

    • Use custom workspace to share the same workspace
    • Block build when up/downstream project is building to avoid overwriting

    If you'd also like to attach test results to job 1 in case it was successful, add in post build steps in job 1 Aggregate downstream test results.

    0 讨论(0)
  • 2021-01-13 19:32

    In a normal configuration, if Build Step 1 fails, Build Step 2 will not execute anyways.

    And if Build Step 2 (Test) fail, the build will be marked "Unstable", not "Failed".

    Email-ext already supports triggers for these.

    • Scroll to your Editable Email Notification section.
    • Click Advanced Settings... button.
    • Look under Triggers section.
    • Click Add Trigger button.

    You want to configure a trigger for "Failure" and a trigger for "Unstable" (you will also probably want a trigger for "Success")

    In your "Failure" trigger, write the email content you want for when the build fails (Build Step 1 failure will cause this for you).
    In your "Unstable" trigger, write the email content you want for when the test cases fail.
    In your "Success" trigger, write the email content you want for when everything was successful and you want to send the test report.

    Alternative:
    Or you can look into Any Build Step plugin (which should allow post-build actions, like email-ext, to be executed as a build step), and Conditional Build Step plugin (which allows to create conditions for each build step). Combine the two and create conditions when you want to trigger the email-ext build step. However I have not tried this and can't guarantee this will work.

    0 讨论(0)
提交回复
热议问题