Passing variable from shell to email-ext in Jenkins

Passing variable from shell to email-ext in Jenkins



I have Jenkins job that has execute shell part in which I have some variable
BUILD that is dynamically populated.



After build execution, I want to pass this variable to email-ext plugin Default Content to able to show it's value.



I've tried couple of ways without a success:



Any idea on how to do this?




4 Answers
4



You can pass build parameters to email ext plugin by using:



$ENV,var="CAPITALIZED:VAR_NAME"



In that way i see the variable value in the received mail.





Can you expand on this a bit by including a concrete example please?
– Taegost
Jun 22 '16 at 12:26





An example would indeed be helpful to understand how this works.
– Chris Giddings
Mar 10 '17 at 15:29





In this specific case, $ENV, var="BUILD" should do the job.
– toppur
Nov 29 '17 at 21:25


$ENV, var="BUILD"



Use EnvInject Plugin to read the variable from a file, after you write that file in the "shell part".



In general, environment variables never go from child process back to parent process, this is basic feature of both Windows and Unix operating system families. Child always gets a copy of parent's environment, and if it modifies it, it modifies it's own copy (which is then copied to any child process if it launches any, etc). But to get changes back, some other method must be used, such as child writing desired changes to a file, which is then parsed by parent, which can then edit it's own environment based on it.





No need for that. I've found easier way to do this. Email-ext plugin supports pre email script where Groovy code can be written. So in the shell part I'm writting data into the file and with Groovy script, I'm reading that data and passing to the MimeMessage variable: String fileContents = new File("file.txt").text msg.setText(fileContents,"UTF-8");
– Bakir Jusufbegovic
Apr 26 '13 at 9:41





Can you share the complete groovy script, to load the variable from the file
– user2400564
May 23 '16 at 2:42



Simple and easy:



In your "Execute Shell"


echo "test log" > /some/file/path/logFile.txt



Then in your "Editable Email Notification-Default Content"


$FILE,path="/some/file/path/logFile.txt"



Build and you will receive a email with content "test log"



To see more email tokens, you can click the question mark beside "Content Token Reference" in "Editable Email Notification" section.



In my case, I'm not the administrator, then I can't install plugins. But can be done with a workaround.



In Content Token Reference help you can found an useful tool.


Content Token Reference


$PROPFILE,file="FILENAME",property="PROPERTYNAME"



Expands to the value of a property in a property file. The filename is
relative to the build workspace root.



Then save values in a property file inside Build > Execute Shell:


Build > Execute Shell


rm -f $WORKSPACE/env.properties
touch $WORKSPACE/env.properties
store="/opt/current/store"

echo "store.folder=$store" >> $WORKSPACE/env.properties

echo "$store"



And read it from Post-build Actions > Editable Email Notification with:


Post-build Actions > Editable Email Notification


$PROPFILE,file="env.properties",property="store.folder"



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế