Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a jenkins multibranch pipeline with a monorepo

I have a project in a monorepo with 2 artifacts : a frontend and a backend.

my-project
  frontend
    Jenkinsfile
  backend
    Jenkinsfile

I'd like to use Blue Ocean and multibranch pipeline but is there a way to use two Jenkinsfile and two pipelines ? Afaik, the Jenkinsfile need to be at the root of the repo.

Otherwise, I will use classic pipeline but I will need to create a new pipeline for each new branch, which is painful.

like image 990
Yann Moisan Avatar asked Nov 07 '22 22:11

Yann Moisan


1 Answers

Create two multibranch-pipelines: MyProjectFrontEnd and MyProjectBackEnd.

Then in the Jenkinsfile you have the following

#!/usr/bin/env groovy
// Get MyProjectFrontEnd from MyProjectFrontEnd/master
switch(env.JOB_NAME.split("/")[0])
{
  case 'MyProjectFrontEnd':
    project = 'front'
    break
  case 'MyProjectBackEnd':
    project = 'back'
    break
  default
    project = ''
    break
}

if (project == 'front') {
  // Place your build steps here for front
}

if (project == 'back') {
  // Place your build steps here for back
}

Now your single Jenkinsfile will determine which pipeline job is building it and then run the correct pipelines.

Alternatively you can make a single pipeline where you just instantiate the correct variables in the switch so you build the correct artifacts.

Having not used Blue Ocean, I'm not sure how well these pipelines visualize.

like image 110
pdross Avatar answered Nov 15 '22 11:11

pdross