As part of a Jenkins build process we run a couple Windows batch scripts and would like to report some information about these intermediate steps in the email that gets send out by Jenkins at the end.
I thought a simple approach would be to set a Windows environment variable in the batch step and we managed to do so using PowerShell as in:
powershell.exe -Command "& {[Environment]::SetEnvironmentVariable('ThisIsATest', 'TestValue', 'Machine')}"
When executed in a "Execute Windows batch command" build step this correctly sets the environment variable "eventually". By that I mean if I remote into the build server I can verify that the value was created / modified as expected during each build.
However, attempting to use the value in the "Editable Email Notification" step under "Post-build Actions" by adding
Our test value: ${ENV, var="ThisIsATest"}
to the "Default Content" section does not give the correct result. Using
Print full environment: ${ENV}
also shows that the value has ??not yet?? been created.
Even stranger is that multiple runs do not pick up the environment variable in question at all - even though I can clearly see it in the remote session (and track changes to it etc.).
Questions:
Would there be other ways of achieving our goal:
"Report general success/failure when compile/unit tests where OK/failed but also report additional info from intermediate steps in the email body"?
Or maybe explain the odd (at least to me) behavior with regards to the email plugin not picking up environment variables that one would expect it to? (To maybe give some new ideas on where to look for workarounds)
Thanks for taking the time to read this. As always, any advice is appreciated.
-T
Environment variables set inside a build step do not propagate outside under the 'normal' circumstances. You can do the following:
VAR=VALUE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With