将图像嵌入到电子邮件正文詹金斯管道中

编程入门 行业动态 更新时间:2024-10-27 14:34:25
本文介绍了将图像嵌入到电子邮件正文詹金斯管道中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要通过管道从Jenkins在电子邮件中添加图像作为电子邮件正文而不是附件. 我正在Jenkins管道中使用emailext插件,下面是我正在使用的代码.

I need to add an image in email as email body not as attachment, from Jenkins via pipeline. I am using emailext plugin in Jenkins pipeline, below is the code I am using.

emailext ( subject: "test email", body: """ <html> <body> <p>please find attached score: Job '${env.JOB_NAME}':</p> <p> The last commit was by ${last_commit_user} </p> <p>Please check jenkins console at "</p> <p> For detailed report on this analysis, visit "</p> </body> </html> """, to: email_recipients, attachmentsPattern: '${BUILD_NUMBER}.jpg' )

我不想使用作为附件附带的"attachmentsPattern", 我尝试使用,

I do not want to use "attachmentsPattern" , that comes as an attachment, I tried using,

body: """ <html> <img src="image_name.jpg" > </html> """

这只是我电子邮件中的蓝框,我给出了相对于我的Jenkins工作区的正确图像路径, 我试图寻找相关解决方案,但徒劳

That comes only as blue box in my email , I am giving proper image path relative to my Jenkins workspace, I tried to search relevant solutions but in vain

请告知

推荐答案

您需要将映像转换为Base64.我是用python做的.

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())

这将写入文件"image.html".然后,您可以将此文件追加到中.在我的管道中,我这样做是这样的:

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"}

更多推荐

将图像嵌入到电子邮件正文詹金斯管道中

本文发布于:2023-11-09 03:07:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571228.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:金斯   道中   图像   电子邮件   正文

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!