我需要通过管道从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"}更多推荐
将图像嵌入到电子邮件正文詹金斯管道中
发布评论