I am trying to utilize Exit code to set build unstable in job -> publishers -> postBuildScripts -> steps -> shell -> advance option to set my build unstable based on a condition.
I have the script below.
...
postBuildScripts {
                onlyIfBuildSucceeds(false)
                steps {
                  shell('echo "Before exit 1"\n' +
                        'if [ ! condition ]; then\n' +
                        'echo failed-condition\n' +
                        'exit 1\n' +
                        'fi'
                       )
                }
            }
...
On executing the above DSL script, I get as below in jenkins

With the above script exit 1, the build fails. But I wanted to make it unstable and I DO NOT want to use markBuildUnstable(true). I wanted to mark build unstable based on certain exit codes only. I can do it by setting the exit code manually to 1 like below
 After this, the build is marked unstable.
After this, the build is marked unstable.
I'm looking for script to set this field through scripts and not manually as I have many jobs.
Can someone please help me on this with suggestions?
 
     
    