A script generates a properties
file to work-space in an Execute shell
block in the Build
section. This file is available at work-space after script execution and in case of Failed
build (Conditional steps (multiple)
block in the Build
section) this properties file will be injected. My Jenkins job sends an E-mail (Editable Email Notification
block) in case if Failed
build and it should contains the variable from properties file but it doesn't see this variable. FYI: This block can use other environment variables.
I have cross-checked the properties file and it contains the required variable in every case.
Properties file in work-space:
Environment variable injection from properties file:
This Steps to to run if condition is met
block contains more other actions and these work fine. It means the running can reach this block.
Editable Email Notification block in Post-build:
If I check the Environment Variables
option in a build, I can see the variable:
But when I get the mail, it doesn't contain the variable:
Any idea how can I solve it or what should I change?
NOTE: The variable is unique and not really related to Gerrit
so I cannot use another variable which comes form Gerrit
. Just the name of var is a little tricky.
I have found the answer for my question. The Jenkins
or the plugin has limitation. It cannot handle the Failure state. If the previous execute shell
block is failed then the running won't reach the Conditional steps (multiple)
block.
On the other hand, I have found a "workaround" for this problem.
1. step
You need to exit from the Execute shell
block with a specific return code. Eg.: 111
2. step
You need to set the Exit code to set build unstable
filed to your specific exit code. (You can find this field in advanced option of Execute shell
block.) As you can see in the below picture.
3. step
Set the Conditional steps (multiple)
block to handle the Unstable
state. With this solution the running is able to run into Conditional steps (multiple)
block.
4. step
Create an Execute shell
block inside the Conditional steps (multiple)
block after you prepare everything what you want in case of job failed. It means after this block your job status changes to Failed
from Unstable
.
Whit this solution you can handle the failed job and in the end you will get a real failed job (not unstable).
Not the most elegant solution but it works.