11

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"
            }
        }
    }
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Anton Matosov
  • 1,685
  • 1
  • 20
  • 19

2 Answers2

15

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

Community
  • 1
  • 1
Anton Matosov
  • 1,685
  • 1
  • 20
  • 19
  • 3
    Very helpful, but any idea why snipped Generator still generate old code? A bug in it? – DelphyM Apr 16 '19 at 22:05
  • 5
    I've raised this issue: https://issues.jenkins-ci.org/browse/JENKINS-35393 – DelphyM Apr 16 '19 at 23:36
  • 2
    Any alternative that allows to use the old syntax `[$class: 'Foo', arg1: 'something', ...]`? I am in the need of using `HudsonNotificationProperty` – Ordiel Oct 02 '19 at 13:55
  • While I'm not sure if this is officially supported I think you just need to move the properties block to be before the pipeline DSL declaration and it will work. For an example using the HudsonNotificationProperty see [this comment](https://issues.jenkins.io/browse/JENKINS-41939?focusedCommentId=407357&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-407357) – MarkRx Apr 06 '21 at 23:50
4

its work for me.

properties([parameters([choice(choices: 'test\ndeploy', name: 'baranch')])])
pipeline{
agent any

stages{
    stage('param check'){
        when {
            expression{
                params.baranch == 'test'
            }
        }
        steps{
            echo "testing"
    }
    }
}

}

nikhil
  • 131
  • 4