5

We are looking into the Jenkins Pipeline type of projects and were wondering if the Jenkinsfile has to be a part of the repository?

We have 20 java projects having a Jenkinsfile that is for 99% the same. Apart from the git repository, everything else in the Jenkinsfile is the same.

It just feels strange that you have to clone the whole repository to get the Jenkinsfile. And then the Jenkinsfile itself clones the repository again to build the project.

Is there some documentation on this or best practices?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Lieven Cardoen
  • 25,140
  • 52
  • 153
  • 244
  • 1. Split your build script for a project into two parts. Global part would be outside git and shared between all/many jobs/branches/projects, whatever. Local part should stay in git. Global config at some point loads the local from git and gives it control. – Gena Batsyan May 04 '17 at 16:13
  • 2. Don't use multibranch pipeline. Ever. Use Job-DSL-Plugin + pipeline. – Gena Batsyan May 04 '17 at 16:14
  • Neither comment answers the question. Should it be added to the repository? I have no idea from either of these comments. (I'm new to Jenkins, too.) – MiguelMunoz Nov 03 '17 at 02:15
  • Also, the comment "Don't use multibranch pipeline. Ever" might be very good advice, but it's not much use if you don't explain why. I'd love to hear what the advantages of Job-DSL-Plugin are, or what the disadvantages of multibranch are. – MiguelMunoz Nov 03 '17 at 22:25

2 Answers2

1

Admittedly this is a bit of necromancy as this question is over a year old but...

I don't think you can do this in the multibranch pipeline. The description of the script path reads:

Relative location within the checkout of your Pipeline script. Note that it will always be run inside a Groovy sandbox. Default is Jenkinsfile if left empty. (just use checkout scm to retrieve sources from the same location as is configured here)

Since this question was posted some changes have been made to jenkins so that it only clones the repo if you are a person who is allowed to make changes to the Jenkins script (you can configure your jenkins as to how it determines this). Which is great for people who aren't allowed to make changes to the jenkins file as they skip the initial clone and checkout. Of course if you are allowed to make changes, this doesn't help much. And there is a potential issue in that someone can make a change to the Jenkins script but the changed script wont get run until it is merged into the master branch, and if there are any errors, it's too late...

Tom Tanner
  • 9,244
  • 3
  • 33
  • 61
-1

There are two ways to use the Jenkinfile:

  1. using a groovy script
  2. using a groovy script with SCM

You can also use Jenkins Job-builder plugin to automate jobs, pipeline projects and so on.. Jenkins Job Builder In this case, you have to just change the repository and the remaining configuration remains the same.

Top 10 Best Practices for Jenkins Pipeline Plugin

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
lakshmi kumar
  • 558
  • 6
  • 7
  • 3
    This doesn't answer the title question. Should it be added to the repository? The answer should be either "yes" or "no." Everything else you said is fine, but you can say all of it and still answer the question. (The Top 10 Best Practices link is very useful, and answers a question in the discussion, but even that doesn't answer the title question.) – MiguelMunoz Nov 03 '17 at 22:36