Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing code when a branch is removed in Jenkins' multi branch pipeline

I have a Jenkins that uses multi branch project. That is, when a new branch is created to repository, Jenkins automatically will automatically create a new job for the branch, and remove that job when the branch is removed.

Now, I'd like to run some code when the branch is removed, to clear testing environments that were created when the branch was created. It there a way to do this?

like image 753
Juha Syrjälä Avatar asked Jun 08 '16 11:06

Juha Syrjälä


Video Answer


2 Answers

Not without writing plugin code I think. If you are interested, the relevant extension point would be OrphanedItemStrategy from the cloudbees-folder plugin.

like image 181
Jesse Glick Avatar answered Oct 22 '22 00:10

Jesse Glick


Nowdays there is multibranch-action-triggers-plugin. This seems have the functionality I asked for. Not tested though.

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.

like image 33
Juha Syrjälä Avatar answered Oct 22 '22 01:10

Juha Syrjälä