Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Multi-branch: How do I add functionality to branch creation/deletion?

Multibranch pipeline Jenkins screensnippet

I am setting up a Jenkins multi-branch instance which needs to allocate a resource on branch job creation when a new branch is detected by the https://wiki.jenkins.io/display/JENKINS/Pipeline+Multibranch+Plugin plugin (version 2.21), and deallocate it when the branch job is deleted by the Multi-branch pipeline when the branch is not present in Git any more.

(To be precise, we need to ship the built binaries to an OpenShift deployment which needs to be explicitly set up and destroyed for each branch).

I have looked at the documentation, but not yet found the location where this can be configured. To my untrained eye, this would make sense to be a "stage" outside the "stages" node, but it is the same for all builds, so it could also go outside Jenkinsfile.

How can I do this?

like image 290
Thorbjørn Ravn Andersen Avatar asked Jul 15 '19 12:07

Thorbjørn Ravn Andersen


People also ask

How do I configure multiple branches in Jenkins?

Head over to your Jenkins instance and create a new item. Enter a name for the job, and select the “Multibranch Pipeline” option at the end of the screen. Then, click on the OK button. In the next screen, go to the “Branch sources” tab, click on the “Add source” button, and choose “Git” from the dropdown menu.

How do you add parameters to the Multibranch pipeline?

If you want to add new parameters you have to do it using properties in Jenkinsfile - goto <JENKINS URL>/pipeline-syntax and generate code for the properties step.

Which enables you to implement different Jenkinsfiles for different branches of the same project?

The Multibranch Pipeline project type enables you to implement different Jenkinsfiles for different branches of the same project. In a Multibranch Pipeline project, Jenkins automatically discovers, manages and executes Pipelines for branches which contain a Jenkinsfile in source control.

Which of the below could be the use case of multi branch pipeline?

Multibranch Pipeline Vs. It can be use used for Gitlab, Bitbucket teams, or Gitea organization. Mullitbranch pipleine can only configure pipelines for a single Git repository. Whereas a Jenins Github organization project can automatically configure multi-branch pipelines for all the repos in a Github organization.


1 Answers

You can use the MultiBranch Action Triggers plugin. With this plugin you run external jobs on branch creation/deletion. You need to create external pipelines which will do things on OpenShift.

like image 115
Aytunc Beken Avatar answered Oct 16 '22 23:10

Aytunc Beken