How to mark a build unstable in Jenkins when running shell scripts

后端 未结 14 2137
情歌与酒
情歌与酒 2020-11-27 11:31

In a project I\'m working on, we are using shell scripts to execute different tasks. Some are sh/bash scripts that run rsync, and some are PHP scripts. One of the PHP script

14条回答
  •  执笔经年
    2020-11-27 12:06

    As a lighter alternative to the existing answers, you can set the build result with a simple HTTP POST to access the Groovy script console REST API:

        curl -X POST \
         --silent \
         --user "$YOUR_CREDENTIALS" \
         --data-urlencode "script=Jenkins.instance.getItemByFullName( '$JOB_NAME' ).getBuildByNumber( $BUILD_NUMBER ).setResult( hudson.model.Result.UNSTABLE )" $JENKINS_URL/scriptText
    

    Advantages:

    • no need to download and run a huge jar file
    • no kludges for setting and reading some global state (console text, files in workspace)
    • no plugins required (besides Groovy)
    • no need to configure an extra build step that is superfluous in the PASSED or FAILURE cases.

    For this solution, your environment must meet these conditions:

    • Jenkins REST API can be accessed from slave
    • Slave must have access to credentials that allows to access the Jenkins Groovy script REST API.

提交回复
热议问题