简体   繁体   English

在Jenkins中进行后期构建后执行Shell脚本

[英]Execute Shell Script after post build in Jenkins

I am trying to execute a shell script if either the build pass or fails after post-build in Jenkins. 我试图执行一个shell脚本,如果构建通过或在Jenkins后构建后失败。 I cannot see this option in post build to execute some shell script except for running a target. 我没有在post build中看到这个选项来执行一些shell脚本,除了运行目标。

Very easily done with Post build task plugin. 使用Post build任务插件很容易完成。

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. 您还可以使用Groovy Post Build运行任意命令 - 这将使您可以在运行时进行大量控制等等。 We use that to run a 'finger of blame' shell script in the case of failed or unstable builds. 在构建失败或不稳定的情况下,我们使用它来运行“责备手指”shell脚本。

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. 我自己使用PostBuildScript插件在构建存档工件和发布测试结果后运行git clean -fxd My Jenkins slaves have SSD disks, so I do not have the room keep generated files in the workspace. 我的Jenkins奴隶有SSD磁盘,所以我没有房间保持工作区中生成的文件。

You should be able to do that with the Batch Task plugin . 您应该可以使用Batch Task插件执行此操作

  1. Create a batch task in the project. 在项目中创建批处理任务。
  2. Add a "Invoke batch tasks" post-build option selecting the same project. 添加“调用批处理任务”构建后选项,选择同一项目。

An alternative can also be Post build task plugin. 另一种选择也可以是Post build task插件。

You'd have to set up the post-build shell script as a separate Jenkins job and trigger it as a post-build step. 您必须将构建后的shell脚本设置为单独的Jenkins作业,并将其作为构建后步骤触发。 It looks like you will need to use the Parameterized Trigger Plugin as the standard "Build other projects" option only works if your triggering build is successful. 看起来您需要使用参数化触发器插件,因为标准的“构建其他项目”选项仅在触发构建成功时才有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM