Send error message by email on on_error step hook

Hello!

I have question about using on_error

i have test pipeline that which ends with error:

How i can grab error message and send it by emeil on_error step hook?

Pipeline example:

groups: []
resources:
- name: resource-gist
  type: git
  source:
    branch: master
    skip_ssl_verification: true
    uri: https://github.com/some_repo
- name: send-an-email
  type: email
  source:
    from: from@example.com
    smtp:
      anonymous: true
      host: smtp.example.com
      port: "25"
      skip_ssl_validation: true
    to:
    - my_email@@example.com
resource_types:
- name: email
  type: docker-image
  source:
    repository: pcfseceng/email-resource
    tag: latest
jobs:
- name: job-error
  public: true
  plan:
  - aggregate:
    - get: resource-gist
      trigger: true
      version: every
  - aggregate:
    - task: task-errot
      config:
        platform: linux
        image_resource:
          type: docker-image
          source:
            repository: ubuntu
        run:
          path: source-code
          args:
          - pwd
      on_error:
        do:
        - put: send-an-email
          params:
            body_text: 'Build error in concourse: ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME}/${BUILD_NAME}'
            subject_text: 'Build error in concourse: ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME}/${BUILD_NAME}'
      on_failure:
        do:
        - put: send-an-email
          params:
            body_text: 'Build failure in concourse: ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME}/${BUILD_NAME}'
            subject_text: 'Build failure in concourse: ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME}/${BUILD_NAME}'
      on_success:
        do:
        - put: send-an-email
          params:
            body_text: 'Build success in concourse: ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME}/${BUILD_NAME}'
            subject_text: 'Build success in concourse: ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME}/${BUILD_NAME}'

In another pipeline we use:

  • put: send-an-email
    params:
    subject: generated-subject-file
    body: generated-body-file

And it’s working, but how i can grab orror message from previous post to file and send it in message body?

That error is from concourse itself, I don’t think you can capture it.