development

Jenkins에서 빌드 후 셸 스크립트 실행

big-blog 2020. 10. 17. 11:41
반응형

Jenkins에서 빌드 후 셸 스크립트 실행


Jenkins에서 빌드 후 빌드가 통과되거나 실패하면 쉘 스크립트를 실행하려고합니다. 타겟 실행을 제외하고 일부 쉘 스크립트를 실행하기 위해 빌드 후이 옵션을 볼 수 없습니다.


포스트 빌드 작업 플러그인 으로 매우 쉽게 수행 할 수 있습니다 .

Jenkins- "포스트 빌드 작업"옵션


Groovy Post Build를 사용하여 임의의 명령을 실행할 수도 있습니다 . 그러면 실행시기 등을 제어 할 수 있습니다. 빌드가 실패하거나 불안정한 경우 '비난의 손가락'셸 스크립트를 실행하는 데 사용합니다.

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
}

(우리의 명령은 마지막 안정된 빌드 날짜와 현재 시간을 매개 변수로 사용하므로 빌드를 손상시킬 수있는 사람을 조사 할 수 있지만 비슷한 방식으로 원하는 명령을 실행할 수 있습니다.)


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.


You should be able to do that with the Batch Task plugin.

  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.


빌드 후 셸 스크립트를 별도의 Jenkins 작업으로 설정하고 빌드 후 단계로 트리거해야합니다. 표준 "다른 프로젝트 빌드"옵션은 트리거링 빌드가 성공한 경우에만 작동 하므로 매개 변수화 된 트리거 플러그인 을 사용해야하는 것 같습니다 .

참고 URL : https://stackoverflow.com/questions/11160363/execute-shell-script-after-post-build-in-jenkins

반응형