Email indentation issue in yaml script in azure devops

66 Views Asked by At

We have used we script in yaml but am getting email with oneline content ( body) I need line breaks in email body.

  - template: /templates/python-v1
  - template: /templates/sendEmail
    parameters:
      to: ${{ parameters.to }}
      body: "Hi Team, This pull request has encountered errors: $(ERRORMESSAGE) Kindly address these issues and resubmit the pull request. Thank you. Sincerely, [DevOps Team]"
      from : ${{ parameters.from }}
      subject : ${{ parameters.subject }}

We have used we script in yaml but am getting email with oneline content ( body) I need line breaks in email body.

1

There are 1 best solutions below

3
wade zhou - MSFT On

You can use "|" after body to define the content.

Main yaml:

steps:
- template: templates/sendEmail.yml
  parameters:
    to: ${{ parameters.to }}
    body: |
      Hi Team, This pull request has encountered errors: 
      $(ERRORMESSAGE) 
      Kindly address these issues and resubmit the pull request. 
      Thank you. 
      Sincerely, 
      [DevOps Team]
    from : ${{ parameters.from }}
    subject : ${{ parameters.subject }}

Template yaml:

parameters:
- name: to  # defaults for any parameters that aren't specified
  default: ''
- name: from
  default: ''
- name: subject
  default: ''
- name: body
  default: ''

steps:
- task: SendEmail@1
  inputs:
    To: ${{ parameters.to }}
    From: ${{ parameters.from }}
    Subject: ${{ parameters.subject }}
    Body: ${{ parameters.body }}
    BodyAsHtml: false
    AddAttachment: false
    SmtpServer: 'smtp-mail.outlook.com'
    SmtpUsername: '$(useremail)'
    SmtpPassword: '$(pwd)'

enter image description here

enter image description here