How to load dynamic Jenkinsfile during a build

Viewed 5027

I'm trying to create a Jenkins pipeline job that uses different Jenkinsbuild files depending on the job parameter. Is there a way to load the Jenkins build file during the execution of the job, something like:

node {
   stage("Determine build parameter") {
      String jenkinsFile = .....
   }
   // here the Jenkins build file should be loaded
   loadSomeHowBuildFile jenkinsFile

   // ... and then the pipeline steps defined in the jenkinsFile are executed 
}

It would be really great is this will work...

1 Answers

I found the solution which is quite simple. Jenkins only needs to load the file

node {
   stage("Determine build file") {
      String jenkinsFile = /path/to/Jenkins/build/file
   }
   // Here the Jenkins build file is loaded and executed
   load jenkinsFile
}
Related