Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 647
Goutham Nithyananda Avatar asked Jan 06 '23 03:01

Goutham Nithyananda


1 Answers

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.

like image 61
Rik Avatar answered Jan 14 '23 00:01

Rik