Execute Shell Script after post build in Jenkins

后端 未结 5 911
天涯浪人
天涯浪人 2020-12-04 23:39

I am trying to execute a shell script if either the build pass or fails after post-build in Jenkins. I cannot see this option in post build to execute some shell script exce

5条回答
  •  攒了一身酷
    2020-12-05 00:03

    You can also run arbitrary commands using the Groovy Post Build - and that will give you a lot of control over when they run and so forth. We use that to run a 'finger of blame' shell script in the case of failed or unstable builds.

    if (manager.build.result.isWorseThan(hudson.model.Result.SUCCESS)) {
      item = hudson.model.Hudson.instance.getItem("PROJECTNAMEHERE")
      lastStableBuild = item.getLastStableBuild()
      lastStableDate = lastStableBuild.getTime()
      formattedLastStableDate = lastStableDate.format("MM/dd/yyyy h:mm:ss a")
      now = new Date()
      formattedNow = now.format("MM/dd/yyyy h:mm:ss a")
      command = ['/appframe/jenkins/appframework/fob.ksh', "${formattedLastStableDate}", "${formattedNow}"]
      manager.listener.logger.println "FOB Command: ${command}"
      manager.listener.logger.println command.execute().text
    }
    

    (Our command takes the last stable build date and the current time as parameters so it can go investigate who might have broken the build, but you could run whatever commands you like in a similar fashion)

提交回复
热议问题