4

I'm setting up a development environment where I have Jenkins as CI server (using pipelines), and the last build step in Jenkinsfile is a deployment to staging. The idea is to have a staging environment for each branch that is pushed.

Whenever someone deletes a branch (sometimes after merging), Jenkins automatically removes its respective job.

I wonder if there is a way to run a custom script before the automatic job removal, then I would be able to connect to the staging server and stop or remove all services that are running for the job that is going to be deleted.

mathop
  • 71
  • 6
  • 3
    Possible duplicate of [Executing code when a branch is removed in Jenkins' multi branch pipeline](http://stackoverflow.com/questions/37701289/executing-code-when-a-branch-is-removed-in-jenkins-multi-branch-pipeline) – mathop Dec 08 '16 at 05:17
  • As mentioned in that linked answer, you'd need to write your own code — or more generically than the orphaned item strategy, you could write an [`ItemListener`](http://javadoc.jenkins.io/hudson/model/listeners/ItemListener.html). – Christopher Orr Dec 08 '16 at 16:21

1 Answers1

2

The plugin multibranch-action-triggers-plugin might be worth a look.

This plugin enables building/triggering other jobs when a Pipeline job is created or deleted, or when a Run (also known as Build) is deleted by a Multi Branch Pipeline Job.

Juha Syrjälä
  • 33,425
  • 31
  • 131
  • 183