Execute Shell Script after post build in Jenkins Execute Shell Script after post build in Jenkins jenkins jenkins

Execute Shell Script after post build in Jenkins


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)


If I'm reading your question right, you want to run a script in the post build actions part of the build.

I myself use PostBuildScript Plugin for running git clean -fxd after the build has archived artifacts and published test results. My Jenkins slaves have SSD disks, so I do not have the room keep generated files in the workspace.