Send Gitlab-CI artifacts via e-mail

眉间皱痕 提交于 2021-02-18 11:36:07

问题


Our Gitlab pipeline generates some performance graphs, which I would like to be sent to every team member via e-mail. So far, they are marked as artifacts so Gitlab keeps them. Is there any way within Gitlab to achive this? Or should I do that within the job script?


回答1:


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.




回答2:


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 <gitlab@example.com>'
      -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.



来源:https://stackoverflow.com/questions/45844000/send-gitlab-ci-artifacts-via-e-mail

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!