10

I have a project with two folders, that are independent, and needs separate builds in Jenkins (running v2.74)

My structure is

folder
├── project1
│   └── Jenkinsfile
└── project2
    └── Jenkinsfile

When I click "scan organization" in Jenkins, it doesnt discover the Jenkinsfiles in subdirectories.

Here is a sample from the "Scan organization log":

Proposing kg-pipeline
Examining my-test-project

  Checking branches...

  Getting remote branches...

    Checking branch jenkins
      ‘Jenkinsfile’ not found
    Does not meet criteria

    Checking branch master
      ‘Jenkinsfile’ not found
    Does not meet criteria

  2 branches were processed

Finished examining my-test-project

I didnt touch the configuration of the job that scans the organization and finds branches with Jenkinsfiles. Here is the current setting for the project

Jenkinsfile discoverability configuration

My question is: How do I configure Jenkins to see each folder individually? I am also interested in links to example projects set up this way.

Jesper Rønn-Jensen
  • 106,591
  • 44
  • 118
  • 155
  • From looking at the plugin sources here now it looks like that the script path check code considers the path absolut and does not process wildcards. So if that is correct the plugin still only considers 1 Jenkinsfile per repository. This is an unfortunate limitation. – Thorbjørn Andersen - UFST Jan 17 '23 at 12:52

3 Answers3

15

There is a simple solution.

  1. go to JENKINS_URL/job/JOB_NAME/configure
  2. under Build Configuration, select by Jenkinsfile for Mode
  3. under Script Path, set it to DIR_NAME/Jenkinsfile

For instance, if you had your Jenkinsfile inside a src directory, then you would set it to src/Jenkinsfile and Jenkins will be able to find the Jenkinsfile now

Ray Kim
  • 1,931
  • 1
  • 13
  • 25
  • Would such a configuration work if I have 2 or more project folders, each with their respective `Jenksfile` . – Sau001 Apr 16 '22 at 21:44
  • It looks like that the plugin only checks for the given name explicitly, and does not process wildcards, so this will still only provide a single Jenkinsfile per repoisitory. – Thorbjørn Andersen - UFST Jan 17 '23 at 12:58
1

Currently trying to set up the same thing - this might help, even though it's not a complete answer:

According to this you should be able to setup two Multibranch Pipeline Projects, each with the configuration Mode "by Jenkinsfile".

Support for using custom paths for the Jeninsfile was added in JENKINS-34561

Martin
  • 138
  • 6
0

You can add more than one "Pipeline Jenkinsfile" under Project Recognizers with your paths to Jenkins files.

Gunjan
  • 1
  • 1
  • 1
    Can you please add more details explaining how this answers the question ? – Manoj Choudhari Feb 01 '19 at 17:40
  • In an Organization Folder, when you are scanning multiple repositories - different repos may have Jenkinsfile at different locations. Using multiple project recognizers solves this for you to be able to scan all repos in your organization when they have different structures. However, if you expect multiple jenkins files to be loaded from the same repo, unfortunately this cannot be done in one Organization Folder setup – Gunjan Feb 12 '19 at 14:46
  • `Multiple Jenkinsfile per repository` is still being explored: https://issues.jenkins-ci.org/browse/JENKINS-43749?page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel&showAll=true – Jesse Chisholm Apr 20 '20 at 20:22