问题
It seems like now you can only have a single Jenkinsfile in a single location in your project when using Multibranch type.
Is there a way to configure so I can place the Jenkinsfile somewhere else than in the root of the project under the name Jenkinsfile. There's hope, as there's an option of Fixed Configuration, maybe this is a feature for the future, but I would much appreciate the option, as in the current situation I do not have the option to run everything as one nicely compiled pipeline due to the size of the repo. I'm thinking of having multiple Jenkins jobs against the same repository.
-- Marcus
回答1:
Starting with Pipeline: Multibranch plugin version 2.15, you can specify the Jenkinsfile location in your configuration.
See my answer at https://stackoverflow.com/a/45172149/2141666 and the plugin changelog at https://wiki.jenkins.io/display/JENKINS/Pipeline+Multibranch+Plugin. From the changelog:
2.15 (Jun 01, 2017)
JENKINS-34561 Option to select a script name/path other than Jenkinsfile.
回答2:
I think I've run into a similar problem.
What you can do is to have a different "pipeline" file stored somewhere else. This can be in the same checkout location or a different checkout all together.
In this file you can define methods and you have to close off with "return this" so that the Jenkinsfile that starts can use the second script. Example:
def initialize(){
wrap([$class: 'BuildUser']) {
env.buildUserName = "$env.BUILD_USER"
env.buildUserId = "$env.BUILD_USER_ID"
env.buildUserEmail = "$env.BUILD_USER_EMAIL"
}
}
// Has to exist with 'return this;' in order to be used as library
return this;
In the Jenkinsfile you can then do the following:
def steps
node {
steps = load 'MyJenkinsPipelineScript.groovy'
steps.initialize()
}
Based upon any environment variables you can load different files. I hope this helps.
来源:https://stackoverflow.com/questions/37272120/jenkins-workflow-multibranch-allow-for-specifying-jenkinsfile-path