3

Is it possible to send a e-mail notification if a specific job fails within an azure pipeline?

Basically, i a testing stage in my pipeline where several jobs run in parallel which execute different test suites. Each test suite has a different guy who is responsible and must be notified if it fails.

I could only find notification options on failing the whole pipeline, but that's not what I want to do.

I also don't create any work items at the moment, and I couldn't find a "send-email-task" or something like this.

I could of course write my own script and execute it if a job fails, but I want to know if there is an easier way to solve my problem.

Tobias von Falkenhayn
  • 1,355
  • 5
  • 26
  • 59

3 Answers3

7

I don't think there is an out-of-the-box option like this, but you can use Send Email extension:

- task: SendEmail@1
  displayName: 'Send an email with subject Job A failed!'
  inputs:
    To: 'user@test.com'
    From: 'test@test.com'
    Subject: 'Job A failed!'
    SmtpServer: 'my smtp server'
  condition: failed()
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
3

Since there is no build-in way to do this, I decided to add a small Powershell script which simply executes after the VSTest task in my testing stage. Also thanks to the failed() condition, it will only execute if at least one test failed.

Tobias von Falkenhayn
  • 1,355
  • 5
  • 26
  • 59
  • So did you used custom email like Send-MailMessage -To “” -From “” -Subject “Your message subject” -Body “Some important plain text!” -Credential (Get-Credential) -SmtpServer “” -Port 587 I'm not sure if SMTP server will work with Devops or not. I want to implement with my azure devops release pipeline. – Gaurav Joshi Oct 21 '20 at 23:40
  • yes thats what I did. There was no other way for me. I used a google account. – Tobias von Falkenhayn Oct 22 '20 at 07:33
0

You can also write some external monitopring which will, verify status of your release throu REST API. I did something like this with proper azure function.

Rob Ert
  • 442
  • 5
  • 23
  • Rob can you please help me with how you implement Rest API for notification..? Thanks Gaurav – Gaurav Joshi Oct 20 '20 at 19:16
  • 1
    Please check links: https://learn.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-6.1 Here GET method is described for pipelines: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/pipelines/get?view=azure-devops-rest-6.1 Also you can manually trigger new custom event which will be send to proper application insight: https://microsoft.github.io/ApplicationInsights-Python/ – Rob Ert Oct 21 '20 at 20:05