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

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

    I find the most flexible way to do this is by reading a file in the groovy post build plugin.

    import hudson.FilePath
    import java.io.InputStream
    
    def build = Thread.currentThread().executable
    
    String unstable = null
    if(build.workspace.isRemote()) {
        channel = build.workspace.channel;
        fp = new FilePath(channel, build.workspace.toString() + "/build.properties")
        InputStream is = fp.read()
        unstable = is.text.trim()
    } else {
        fp = new FilePath(new File(build.workspace.toString() + "/build.properties"))
        InputStream is = fp.read()
        unstable = is.text.trim()
    }
    
    manager.listener.logger.println("Build status file: " + unstable)
    if (unstable.equalsIgnoreCase('true')) {
        manager.listener.logger.println('setting build to unstable')
        manager.buildUnstable()
    }
    

    If the file contents are 'true' the build will be set to unstable. This will work on the local master and on any slaves you run the job on, and for any kind of scripts that can write to disk.

提交回复
热议问题