It’s hard to answer that question without more context. For example, can you show how you set SCRIPT_RET to the value or RET, and where you try to read the SCRIPT_RET value? That would all have to be in the same context, for example all in the same Freestyle job shell script, or in the same Pipeline Script.
The problem is that I could not override this environment variable with the value returned from my Python script that I call in the Freestyle job shell script as you see below.
This simply does not recognise the environment variable, but treats it as a regular variable. As a result, SCRIPT_RET in the post-build action remains null, as I do not assign something to it at the beginning while creation.
I strongly recommend looking into swapping out to pipeline, you’ll be able to do this, and have much more freedom than a freestyle job (which is now ironically named).
That being said, If i remember my freestyle correctly, you’ll have to execute a shell script, write it to a file, and then use a different plugin to import into your envs. I’m not sure said plugin actually exists. I wrote GitHub - halkeye/jenkins-fileToEnv: Jenkins plugin a long time ago, but never polished it up to release.
That being said, you could do a conditional step (to do notify failure custom logic) and just curl to mattermost, googling says its just a simple post and have more freedom that way.
I am not able to convert it to a pipeline right now, because it will require a bit time, but I will keep this on my mind when I am able to do so. Thank you for your help!