embed image in email body jenkins pipeline

隐身守侯 提交于 2019-12-08 09:33:25

You need to convert your image to Base64. I do it using python.

import base64

base64Img = ''

with open("image.png", "rb") as imageFile:
    base64Img = base64.b64encode(imageFile.read())

with open("image.html", "wb+") as writer:
    writer.write('<img src="data:image/png;base64,'.encode())
    writer.write(base64Img)
    writer.write('">'.encode())

This writes a file ''image.html''. This file you can then append into your <body>. In my pipeline I do it like so:

${FILE,path="image.html"}
Vishnu Priya

Push the image file in workspace directory of jenkins job.
Goto the workspace and click on the image to get the URL.
Place img src="IMAGE_URL" in email template.

To include images into your Jenkins Extended E-mail mails, you have to:

  • Put the images into this Jenkins directory: $JENKINS_HOME/war/images/
  • And then restart Jenkins service

And you can insert the image YOUR_IMAGE.jpg into your groovy-html.template. Note that ${rooturl}static/e59dfe28/images is constant.

<p>Some HTML...</p>
<img src="${rooturl}static/e59dfe28/images/YOUR_IMAGE.jpg"/>
<p>Some HTML...</p>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!