Send Gitlab-CI artifacts via e-mail

There is no way currently to send artifacts via email from the gitlab interface. You will indeed have to send them from your job scripts.
Gitlab can send an email after a pipeline is finished (see in Settings>Integrations>Pipeline emails), but it doesn't attach artifacts.

Another way to share them would be to publish them in gitlab pages from your job script (doc here : https://docs.gitlab.com/ee/user/project/pages/index.html), but it wouldn't send an email.


It seems that a few years down the road nothing has changed yet (or I do not know about it).

send_email:
    stage: notify
    when: on_failure
    script: curl -s --user "api:$MAILGUN_API_KEY" 
      "https://api.mailgun.net/v3/$MAILGUN_DOMAIN/messages"
      -F from='Gitlab <[email protected]>'
      -F to=$GITLAB_USER_EMAIL
      -F subject='Test results + report'
      -F text='Testing some Mailgun awesomeness!'
      -F attachment='@reports/report.html'

There are a few things you need to get this to work:

  • generate an artifact in another job (the file you want to upload; mine is reports/report.html)
  • define the variables MAILGUN_API_KEY and MAILGUN_DOMAIN

I needed something similar so here is a snippet from my pipeline.

I have also documented everything in a blog post. https://medium.com/@vdespa/send-gitlab-ci-reports-artifacts-via-e-mail-86bc96e66511

I hope this helps a bit.