Dim
Dim

Reputation: 4807

Sending email in Jenkins with body from content in file

Ive downloaded plugin for jenkings to sending emails. What I have is 2 files:

ReleaseNotes.txt
config.properties

The first one contains release notes in plain text, the second one contains the same release notes as properties file. I can send them as attachment via this plug in, but I wish to add the content as mail content.

Option 1: Somehow add content of ReleaseNotes.txt to my mail

Option 2: Set new environmental variable from config.properties and add them to mail.

Esther one of the options will satisfy me, can you please help me with one of them? In your answer please not just send me link to plugin but actually help me and explain how to achieve it. I saw some plugins but I struggled using them.

Upvotes: 14

Views: 33962

Answers (4)

Mark VY
Mark VY

Reputation: 1671

With the Editable Email Notification plugin, you can use this syntax in the body:

The file hello.txt has contents ${FILE, path="hello.txt"}
The file hello-$BUILD_NUMBER.txt has contents ${FILE, path="hello-$BUILD_NUMBER.txt"}

Upvotes: 0

abdelatif
abdelatif

Reputation: 21

If you are using Pipeline you can simply use the following script:

emailext (to: '[email protected]', replyTo: '[email protected]', subject: "Email Report", body: readFile("target/site/serenity/index.html"), mimeType: 'text/html');

In my case i was using serenity for reporting

Upvotes: 2

Lewen Zhang
Lewen Zhang

Reputation: 321

With the Email Extension Plugin v2.61 you can just do

<pre>
${FILE, path="file_name.txt"}
</pre>

in the Default Content session and keep the format

Upvotes: 32

Rog&#233;rio Peixoto
Rog&#233;rio Peixoto

Reputation: 2247

You should be able to combine Environment Script plugin with Email-ext plugin to achieve the desired functionality.

Check the generate environment variable from script option in the build environment section.

Then create the script to read the file content, like this:

echo RELEASE_NOTES=$(cat ReleaseNotes.txt)

In the extended email notification configurations section, fill the default content field with your recently created variable $RELEASE_NOTES

Upvotes: 7

Related Questions