5

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Yann Moisan
  • 8,161
  • 8
  • 47
  • 91
  • 1
    This would probably solve your problem, but i m curious what that _internal document_ says https://issues.jenkins-ci.org/browse/JENKINS-43749 – dag Apr 26 '17 at 15:28

1 Answers1

1

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.

pdross
  • 730
  • 6
  • 6