How to set quietperiod on Jenkins Pipeline

Viewed 1252

I have a pipeline with some boolean parameters. I'd like to add the quietPeriod as described in the docs but I'm struggling to get the syntax right. I tried:

properties([
  parameters :[
    booleanParam(name: 'foo', defaultValue: false, description: 'bar')
  ],
  quietPeriod: 10
])

But that yields a java.lang.UnsupportedOperationException: must specify $class with an implementation of interface java.util.List.

Does anyone know how to add this parameter correctly?

2 Answers

Use it as an option in the pipeline as follows:

pipeline {
    agent any
    options {
        quietPeriod(300) //Quiet period in seconds
    }
    stages {
        stage('1') {
            steps {
                println("Hello")
            }
        }
    }
}

From this Jenkins ticket in JIRA it seems like the feature is only available by default when the Declarative Pipeline syntax is used.

As a workaround I found that doing

currentBuild.rawBuild.getParent().setQuietPeriod(210)

works like a charm. You can put it right after setting the properties, like this:

properties([
  parameters :[
    booleanParam(name: 'foo', defaultValue: false, description: 'bar')
  ]
])

currentBuild.rawBuild.getParent().setQuietPeriod(210)
Related