简体   繁体   English

Jenkins Workflow Multibranch允许指定Jenkinsfile路径

[英]Jenkins Workflow Multibranch allow for specifying Jenkinsfile path

It seems like now you can only have a single Jenkinsfile in a single location in your project when using Multibranch type. 现在看来,在使用Multibranch类型时,项目中的单个位置只能有一个Jenkins文件。

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. 有没有办法配置所以我可以将Jenkins文件放在名称为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. 我正在考虑在同一个存储库中拥有多个Jenkins作业。

-- Marcus - 马库斯

Starting with Pipeline: Multibranch plugin version 2.15, you can specify the Jenkinsfile location in your configuration. 从Pipeline:Multibranch插件版本2.15开始,您可以在配置中指定Jenkinsfile位置。

See my answer at https://stackoverflow.com/a/45172149/2141666 and the plugin changelog at https://wiki.jenkins.io/display/JENKINS/Pipeline+Multibranch+Plugin . 见我在回答https://stackoverflow.com/a/45172149/2141666和插件的changelog https://wiki.jenkins.io/display/JENKINS/Pipeline+Multibranch+Plugin From the changelog: 来自更改日志:

2.15 (Jun 01, 2017) 2。15(2017年6月1日)

JENKINS-34561 Option to select a script name/path other than Jenkinsfile. JENKINS-34561选择除Jenkinsfile之外的脚本名称/路径的选项。

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. 在此文件中,您可以定义方法,并且必须使用“return this”关闭,以便启动的Jenkinsfile可以使用第二个脚本。 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: 在Jenkinsfile中,您可以执行以下操作:

def steps
node {
    steps = load 'MyJenkinsPipelineScript.groovy'
    steps.initialize()
}

Based upon any environment variables you can load different files. 根据任何环境变量,您可以加载不同的文件。 I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM