如何正确使用Jenkins管道`options` [英] How to use Jenkins pipeline `options` correctly

查看:253
本文介绍了如何正确使用Jenkins管道`options`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘要生成器为我创建了一个properties块.首次运行报告

Snippet generator created a properties block for me. First run reported

WorkflowScript: 1: The properties section has been renamed as of version 0.8. Use options instead. @ line 1, column 1.
   pipeline {

properties替换为options会导致以下错误:

Replacing properties to optionsresults with the following error:

Errors encountered validating Jenkinsfile:
WorkflowScript: 4: options can not be empty @ line 4, column 5.
   options([$class: 'ThrottleJobProperty',

完整的jenkinsfile供参考

pipeline {
    agent any

    options([[$class: 'ThrottleJobProperty',
            categories: ['xcodebuild'],
            limitOneJobWithMatchingParams: false,
            maxConcurrentPerNode: 0,
            maxConcurrentTotal: 0,
            paramsToUseForLimit: '',
            throttleEnabled: true,
            throttleOption: 'category']])

    stages {
        stage("Empty" {
            steps {
                echo "Do nothing"
            }
        }
    }
}

推荐答案

TLDR

在选项中不再可以使用自定义$class

请注意,不能使用[$class: 'Foo', arg1: 'something', ...]语法,只能使用booleanParam(...)等.

完整选项语法

  • 说明:传统的JobProperty(例如buildDiscarderdisableConcurrentBuilds),声明性的特定选项(例如skipDefaultCheckout)和包装器"(应该包装整个构建,例如timeout.
  • 必需:否
  • 允许:仅顶级pipeline关闭.
  • 参数:无
  • 闭幕:是
  • 关闭内容:一个或多个声明性选项或作业属性配置的序列,使用@Symbol名称作为构造函数.
    • 请注意,不能使用[$class: 'Foo', arg1: 'something', ...]语法,只能使用booleanParam(...)等.
    • 请注意,不能在此处直接使用parameterspipelineTriggers @Symbol.
    • Full Options Syntax

      • Description: Traditional JobPropertys, such as buildDiscarder or disableConcurrentBuilds, Declarative-specifc options, such as skipDefaultCheckout, and "wrappers" that should wrap the entire build, such as timeout.
      • Required: No
      • Allowed In: Top-level pipeline closure only.
      • Parameters: None
      • Takes a Closure: Yes
      • Closure Contents: A sequence of one or more Declarative option or job property configurations, using @Symbol names for constructors.
        • Note that [$class: 'Foo', arg1: 'something', ...] syntax can not be used, only booleanParam(...) and the like.
        • Note that the parameters and pipelineTriggers @Symbols cannot be used here directly.
        • 示例:

          options {
              buildDiscarder(logRotator(numToKeepStr:'1'))
              disableConcurrentBuilds()
          }
          

          来源

          这篇关于如何正确使用Jenkins管道`options`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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