Jenkins Custom Design Piping Recognizers

When you create a Github organization or a Bitbucket team / project, one of the configuration items:

Project Identifiers: Pipeline Jenkinsfile

There are no other options besides the Pipeline Jenkinsfile, however, the fact that this option is even there indicates that developers assume that people write their own "recognizers" for projects that do not have a single "Jenkinsfile" in the top directory repo.

Can someone point me towards any other project recognizers that can be installed and used, or even some details about where to start implementing my own recognizer?

My specific use case is that in one repository we define several workflows that organize code / configuration actions in one repo, and I would like to be able to use the Bitbucket Team command to dynamically scan the repo, find all the *.Jenkinsfile files for all requests branches / pull and fill the necessary conveyors.

For example, the repo contains files:

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

I would like jenkins to create a folder structure:

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

Any thoughts on where I could start by creating a Project Recognizer for this (if possible)?

+5
source share
2 answers

I think you can do this by providing several design 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 might be Groovy Pipeline Sharing Library Plugin ; more information about this plugin can be found on the Shared Libraries Extension .

This approach gives you the opportunity to use your own scripts (classes, stages, etc.), which means that you can define your own flow depending on the repo name, project name, etc.

0
source

At the moment, at least there should be an option to provide an alternate recognizer for Jenkinsfile . This was added in JENKINS-34561 - allow detection of different Jenkinsfile file names . You can see the pull request jenkinsci / workflow-multibranch-plugin / pull / 59 , which may help provide some background information on how recognizers work.

In terms of multiple recognition from a single source, JENKINS-35415 - Several branch projects to a repository with different recognizers and JENKINS-43749 - Support for multiple Jenkinsfiles from the same repository are queries that are very similar to this one.

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

Instead, you need to create a computed folder with a pipeline job for each jenkins file in the branch.

I think APIs should support this if someone wants to strike. The only problem I see is that we may need to configure the branch-api so that the tasks on the branches are undefined types (i.e. a computed folder)

It looks like you will need to implement BranchProjectFactory (example: WorkflowBranchProjectFactory ), which is the factory for ComputedFolder (example: WorkflowMultiBranchProject ).

Good luck

0
source

Source: https://habr.com/ru/post/1267294/


All Articles