Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  1. Passing this ${BUILD} value in Default Content is not recognized (Only Jenkins environment variables are visible in this context)
  2. Defined new Jenkins global environment variable and tried to overwrite its initial value in shell context which apparently is not possible

Any idea on how to do this?

like image 651
Bakir Jusufbegovic Avatar asked Mar 15 '13 16:03

Bakir Jusufbegovic


4 Answers

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.

${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:

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:

${PROPFILE,file="env.properties",property="store.folder"}
like image 115
equiman Avatar answered Oct 14 '22 03:10

equiman


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.

like image 40
GrumpyMelon Avatar answered Oct 14 '22 03:10

GrumpyMelon


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.

like image 1
hyde Avatar answered Oct 14 '22 01:10

hyde


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.

like image 1
Patricio Iglesias Avatar answered Oct 14 '22 03:10

Patricio Iglesias