Goutham Nithyananda
Goutham Nithyananda

Reputation: 939

Pick JenkinsFile from custom location in pipeline plugin of jenkins

Can jenkins pipeline plugin pick jenkinsfile from a custom location and start the build?

i don't want to keep jenkinsfile inside the source code. If there is any change in the source code. jenkinsfile from custom location should be picked and build should be started.

Example:/home/test/jenkinsfile

Upvotes: 4

Views: 12363

Answers (2)

Jesse Chisholm
Jesse Chisholm

Reputation: 4005

I Think there is a way.

  • Once you have run your project with a regular Jenkinsfile, ...
  • Make your new Jenkinsfile.other
  • Go to the Jenkins Dashboard for your repository
  • View the Job Configuration
  • Scroll down to the Build Configuration section
  • Change the name of your Jenkinsfile to your Jenkinsfile.other
  • Run the build.

I haven't tried creating a clone Jenkins Job, and editing that one to have both always available.

Upvotes: 1

Rik
Rik

Reputation: 3887

You can of-course just try to put a custom location (I wouldn't see why it can't) as long as the user has rights to read the location.

If it is a multibranch pipeline, than no. Because indexing is based the presence of a Jenkinsfile (only branches that contain a Jenkinsfile are indexed)

The thought behind having the logic of your build inside your repository is, that this is source controlled together with your sources. When you change something in your sources and this affects your build, than building that specific commit will have all the logic. If you move this outside your repository your build logic and your repository are very likely to get out of sync.

EDIT You can workaround this by adding a Jenkinsfile that will load the other file

Jenkinsfile:

load "/home/test/Jenkinsfile"

However as far as I know, directoriees are relative to the workspace. So if you have any dir("path/to/other/dir"){..} than that will run relative to the workspace of the job, which makes your static Jenkinsfile very confusing to read.

Upvotes: 8

Related Questions