0
votes

In Jenkins job configuration I have written a bat script in the command window of build section. In one of the script commands I set an environment variable as a system environment variable in the server machine as so:

setx Analysis_URL "http://analysis_url/analysis/%analysis_id%.html

My task now is to get this environment variable value back to Jenkins and include it in my post build notification email content. Is there a simple way to do it ?

In my research I have come across the plugin envInject but I think it is used for setting environment variables, is that right ?

UPDATE 1 :

It turned out that the variable could be accessed by a simple $Analysis_URL in the email content, however, that raised another issue as my environment variable changes its value after each job build, but as Jenkins only takes a copy of the system environment variables I keep getting the same variable value after each build in my email content, it only changes after restarting Jenkins. Is there a way to get the updated system environment variables to Jenkins ?

UPDATE 2 :

EnvInject plugin did the job I wanted. These are the steps that I performed:

  1. Build step "batch command window": added command :

echo ANALYSIS_URL=$ANALYSIS_URL > my.properties

  1. Build step "Inject environment variables": in field "Properies File Path"

$WORKSPACE/my.properties

  1. Post-Build Actions: "Editable Email Notification", Field "Default Content":

Current analysis url: $ANALYSIS_URL

3
this method works, there is a typo, $WORDKSPACE/my.properties should be $WORKSPACE/my.propertiesSamurais

3 Answers

1
votes

Have you tried the env.Analysis_URL to access to your environment variable ?

1
votes

Printing Variables in Post Build Email:

  1. Add this to build: execute shell section:
echo count=$count > count.txt
echo distinctcount=$distinctcount > distinctcount.txt

execute shell section

  1. Add this to Inject Environmental Variables section under "Properties File Path":
${WORKSPACE}/count.txt

Properties File Path and do the same also for the second file ${WORKSPACE}/distinctcount.txt (as I have two variables)

Note 1: ${WORKSPACE} is pwd for jenkins and lists the location)

Note 2: You can actually put both variables in just one file by using echo distinctcount=$distinctcount >> count.txt

  1. Call the variable in the "default content" section of "editable email notification":
Count total:$count Distinct Count: $distinctcount

editable email notification

NOTE Be sure you have email setup as "always" under "advanced settings" at the bottom of the email settings, otherwise it only emails upon first success or any failure:

advanced settings email setup as "always"

-1
votes

You can just use: ${yourDefinedVriableName}