How to mark a build unstable in Jenkins when running shell scripts
Modern Jenkins versions (since 2.26, October 2016) solved this: it’s just an advanced option for the Execute shell build step! You can just choose and set an arbitrary exit value; if it matches, the build will be unstable. Just pick a value which is unlikely to be launched by a real process in your build.