如何在许多项目中共享声明式管道 [英] How to share a Declarative Pipeline across many projects

查看:97
本文介绍了如何在许多项目中共享声明式管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在不同存储库中有很多项目,它们共享相同的基本CI工作流,我可以轻松地将其表示为声明性管道:

I have a lot of projects in different repositories which share the same fundamental CI-workflow, which I can easily express as a Declarative Pipeline:

pipeline {
  agent any

  options {
    buildDiscarder(logRotator(numToKeepStr: '20'))
  }

  stages {
    stage('CI') {
      steps {
        echo 'Do CI'
      }
    }

    stage('QA') {
      steps {
        echo 'Do QA'
      }
    }
  }

  post {
    always {
      junit allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml'
      // etc...
    }

    failure {
      echo 'Failure mail'
      // etc
    }
  }
}

我想在所有项目中使用相同的声明式管道,并且能够在一个地方更改管道的定义,并自动在所有项目中使用更改.

I would like to use the same Declarative Pipeline across all my projects and have the ability to change the definition of the Pipeline in just one place and have the changes used in all projects automatically.

本质上,我在项目中要做的事情是:Jenkinsfile是这样的:

Essentially what I would to do in a project;s Jenkinsfile is this:

loadPipelineFromScm 'repository', 'pipeline.groovy'

我已经可以使用共享库来做到这一点,但是之后我将无法再使用声明性管道功能.

I can already do this with shared libraries, but then I'm not able to use Declarative Pipeline features anymore.

是否可以在许多存储库之间共享 Declarative 管道?

Is there a way to share a Declarative Pipeline across many repositories?

推荐答案

使用noober01的建议使视图保持完整时,声明性管道将无法正常运行.例如. when子句将被忽略,因为管道元素应该是顶级的,这意味着它将被解析为脚本管道.

While the views are left intact using the suggestion from noober01 the declarative pipeline will not function properly. E.g. when clauses will be ignored, since the pipeline element is expected to be top-level, meaning it is parsed as scripted pipeline instead.

请参阅Jenkins背后的团队拒绝的以下问题:加载外部声明性管道问题

See the following issue rejected by the team behind Jenkins: loading external declarative pipelines issue

这篇关于如何在许多项目中共享声明式管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆