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

后端 未结 14 2132
情歌与酒
情歌与酒 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:07

    You can just call "exit 1", and the build will fail at that point and not continue. I wound up making a passthrough make function to handle it for me, and call safemake instead of make for building:

    function safemake {
      make "$@"
      if [ "$?" -ne 0 ]; then
        echo "ERROR: BUILD FAILED"
        exit 1
      else
        echo "BUILD SUCCEEDED"
      fi
    }
    
    0 讨论(0)
  • 2020-11-27 12:08

    In my job script, I have the following statements (this job only runs on the Jenkins master):

    # This is the condition test I use to set the build status as UNSTABLE
    if [ ${PERCENTAGE} -gt 80 -a ${PERCENTAGE} -lt 90 ]; then
      echo WARNING: disc usage percentage above 80%
    
      # Download the Jenkins CLI JAR:
      curl -o jenkins-cli.jar ${JENKINS_URL}/jnlpJars/jenkins-cli.jar
    
      # Set build status to unstable
      java -jar jenkins-cli.jar -s ${JENKINS_URL}/ set-build-result unstable
    
    fi
    

    You can see this and a lot more information about setting build statuses on the Jenkins wiki: https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI

    0 讨论(0)
  • 2020-11-27 12:08

    I thought I would post another answer for people that might be looking for something similar.

    In our build job we have cases where we would want the build to continue, but be marked as unstable. For ours it's relating to version numbers.

    So, I wanted to set a condition on the build and set the build to unstable if that condition is met.

    I used the Conditional step (single) option as a build step.

    Then I used Execute system Groovy script as the build step that would run when that condition is met.

    I used Groovy Command and set the script the following

    import hudson.model.*
    
    def build = Thread.currentThread().executable
    build.@result = hudson.model.Result.UNSTABLE
    
    return
    

    That seems to work quite well.

    I stumbled upon the solution here

    http://tech.akom.net/archives/112-Marking-Jenkins-build-UNSTABLE-from-environment-inject-groovy-script.html

    0 讨论(0)
  • 2020-11-27 12:08

    One easy way to set a build as unstable, is in your "execute shell" block, run exit 13

    0 讨论(0)
  • 2020-11-27 12:09
    1. Configure PHP build to produce xml junit report

      <phpunit bootstrap="tests/bootstrap.php" colors="true" >
         <logging>
             <log type="junit" target="build/junit.xml" 
                 logIncompleteSkipped="false" title="Test Results"/>
         </logging>
      
         ....
      
       </phpunit>
      
    2. Finish build script with status 0

      ...
      exit 0;
      
    3. Add post-build action Publish JUnit test result report for Test report XMLs. This plugin will change Stable build to Unstable when test are failing.

      **/build/junit.xml
      
    4. Add Jenkins Text Finder plugin with console output scanning and unchecked options. This plugin fail whole build on fatal error.

      PHP Fatal error:
      
    0 讨论(0)
  • 2020-11-27 12:11

    It can be done without printing magic strings and using TextFinder. Here's some info on it.

    Basically you need a .jar file from http://yourserver.com/cli available in shell scripts, then you can use the following command to mark a build unstable:

    java -jar jenkins-cli.jar set-build-result unstable
    

    To mark build unstable on error, you can use:

    failing_cmd cmd_args || java -jar jenkins-cli.jar set-build-result unstable
    

    The problem is that jenkins-cli.jar has to be available from shell script. You can either put it in easy-to-access path, or download in via job's shell script:

    wget ${JENKINS_URL}jnlpJars/jenkins-cli.jar
    
    0 讨论(0)
提交回复
热议问题