How to use Jenkins pipeline `options` correctly

霸气de小男生 提交于 2021-02-18 21:12:09

问题


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 {

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',

Here is the full jenkinsfile for reference

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"
            }
        }
    }
}

回答1:


TLDR

It's no longer possible to use custom $class in the options

Note that [$class: 'Foo', arg1: 'something', ...] syntax can not be used, only booleanParam(...) and the like.

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.

Example:

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

Source



来源:https://stackoverflow.com/questions/41884503/how-to-use-jenkins-pipeline-options-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!