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

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

问题描述

我在不同的存储库中有很多项目,它们共享相同的基本 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.

基本上我会在项目中做的事情;s 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.

有没有办法在多个存储库之间共享声明式管道?

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天全站免登陆