简体   繁体   English

Jenkins共享库-为options部分创建一个通用函数

[英]Jenkins shared library - create a generic function for the options section

I want to expand our shared library usage - want to add a function that will contain all the options for the pipeline: 我想扩展共享库的用法-想添加一个函数,其中包含管道的所有选项:

options {
        disableConcurrentBuilds()
        timestamps()
        timeout(time: 30, unit: 'MINUTES')
        buildDiscarder(logRotator(numToKeepStr: '30'))
    }

so in my pipeline I will have something like 所以在我的管道中,我会遇到类似

pipeline {
   agent any

   pipelineOptions()

   stages {
       stage('phase1') { 
           steps {               
               sh 'echo Hello World '
           }
       }
   }
}

tried something like , but it didn't work 尝试了类似的东西,但是没有用

//pipelineOptions.groovy
def call() {
        options {
                disableConcurrentBuilds()
                timestamps()
                timeout(time: 5, unit: 'MINUTES')
                //buildDiscarder(logRotator(numToKeepStr: ' params.history'))
                buildDiscarder(logRotator(numToKeepStr: ' 5'))
        }

}

couldn't find how to make it ... , is it possible ? 找不到如何做...,有可能吗?

It isn't possible today to define sections / directives of a declarative pipeline in a shared library. 今天不可能在共享库中定义声明性管道的 / 指令 From the documentation : 文档中

Only entire pipeline's can be defined in shared libraries as of this time. 到目前为止,只能在共享库中定义整个管道。 This can only be done in vars/*.groovy , and only in a call method. 这只能在vars/*.groovy ,并且只能在call方法中完成。 Only one Declarative Pipeline can be executed in a single build, and if you attempt to execute a second one, your build will fail as a result. 单个构建中只能执行一个声明性管道,如果尝试执行第二个声明性管道,则结果将失败。

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

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