本文介绍了具有外部定义的Jenkinsfile的多分支配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个开源项目,该项目位于GitHub上,并使用由詹金斯(Jenkins)控制的构建场进行构建.

I have an open-source project, that resides in GitHub and is built using a build farm, controlled by Jenkins.

我想使用管道以分支方式构建它,但是我不想在代码内存储Jenkinsfile.有没有办法做到这一点?

I want to build it branch-wise using a pipeline, but I don't want to store Jenkinsfile inside the code. Is there a way to accomplish this?

推荐答案

首先,为什么不希望在代码中使用Jenkinsfile?管道和构建文件一样,是代码的一部分.

First of all, why do you not want a Jenkinsfile in your code? The pipeline is just as much part of the code as would be your build file.

除此之外,还可以加载常规文件以将其评估为管道脚本.您可以使用from SCM选项从其他位置执行此操作,然后签出实际代码.但这将迫使您手动处理分支构建.

Other then that, you can load groovy files to be evaluated as a pipeline script. You can do this either from a different location with the from SCM option and then checkout the actual code. But this will force you to manually take care of the branch builds.

另一种选择是拥有一个非常基本的Jenkinsfile,该文件仅签出外部管道.

Another option would be to have a very basic Jenkinsfile that merely checkouts an external pipeline.

您会得到这样的东西:

node{
    deleteDir()

    git env.flowScm
    def flow = load 'pipeline.groovy'
    stash includes: '**', name: 'flowFiles'

    stage 'Checkout'
    checkout scm // short hand for checking out the "from scm repository"

    flow.runFlow()
}

pipeline.groovy文件将包含实际管道的地方看起来像这样:

Where the pipeline.groovy file would contain the actual pipeline would look like this:

def runFlow() {
    // your pipeline code

} 

// Has to exit with 'return this;' in order to be used as library
return this;

这篇关于具有外部定义的Jenkinsfile的多分支配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 13:20