Custom Project Recognisers for Jenkins Multi-branch Pipelines
Asked Answered
P

2

7

When you create a Github Organisation or a Bitbucket Team/Project, one of the configuration items is:

Project Recognizers: Pipeline Jenkinsfile

There are no other options other than "Pipeline Jenkinsfile", however the fact that the option is even there suggests that the developers envisage people writing their own custom 'recognizers' for projects that don't have a single 'Jenkinsfile' in the top directory of the repo.

Can anyone point me in the direction of any other project recognisers that can be installed and used, or even some details on where to start to implement my own recogniser?

My particular use-case is that within a single repository, we define several workflows that orchestrate actions over code / configuration in the one repo, and I would love to be able to use the Bitbucket Team option to dynamically scan the repo, find all the *.Jenkinsfile files across all branches / pull requests and populate the necessary pipelines.

For example, in the repo are the files:

/pipelines/workflow1.Jenkinsfile
          /workflow2.Jenkinsfile
          /workflow3.Jenkinsfile

I would like jenkins to create the folder structure:

 /team/repo/workflow1/master
                     /dev
                     /PR1
           /workflow2/master
                     /dev
                     /feature-xyz

Any thoughts on where I could start with creating a Project Recognizer to do this (if this is even possible) ?

Plight answered 28/4, 2017 at 17:4 Comment(0)
H
0

I think you can do that with providing several Project Recognizers with different names, for example:

Project Recognizers ========================================= **Pipeline Jenkinsfile** Script Path: pipeline/workflow1.Jenkinsfile (or path to the file that contains valide Pipeline steps. ========================================= **Pipeline Jenkinsfile** Script Path: pipeline/workflow2.Jenkinsfile (or path to the file that contains valide Pipeline steps. ========================================= **Pipeline Jenkinsfile** Script Path: pipeline/workflow3.Jenkinsfile (or path to the file that contains valide Pipeline steps.

Another option here, could be Pipeline Shared Groovy Libraries Plugin, more details about this plugin can be found at Extending with Shared Libraries.

This approach gives you ability to use your custom scripts (Classes, steps, etc.) which means that you can define your own flow depending on repo name, project name, etc.

Hitandmiss answered 5/11, 2017 at 21:37 Comment(0)
A
0

As of now, there should at least be the option to provide an alternative recognizer for the Jenkinsfile. This was added in JENKINS-34561 - Allow to detect different Jenkinsfile filenames. You can see the pull request at jenkinsci/workflow-multibranch-plugin/pull/59 which may help provide some background information in how the recognizers work.

In terms of multiple being recognized from a single source, JENKINS-35415 - Multiple branch projects per repository with different recognizers and JENKINS-43749 - Support multiple Jenkinsfiles from the same repository are requests that are very similar to this one.

A comment from Stephen Connolly in JENKINS-43749 says this about it:

What this is asking for is, instead, to create a computed folder with a pipeline job for each jenkinsfile within the branch.

I think the APIs should support that if somebody wants to take a stab at it. The only issue I see is that we may need to tweak the branch-api to allow for the branch jobs to be a non-job type (i.e. computed folder)

It sounds like you will need to implement a BranchProjectFactory (example: WorkflowBranchProjectFactory) that is a factory for a ComputedFolder (example: WorkflowMultiBranchProject).

Good luck!

Anesthetic answered 27/12, 2017 at 22:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.