jenkinsci / persistent-parameter-plugin

https://plugins.jenkins.io/persistent-parameter/
MIT License
7 stars 11 forks source link

Declarative pipeline support #12

Closed ro-kr closed 3 years ago

ro-kr commented 3 years ago

This adds support for declarative pipeline scripts, so that the persistent parameters can be created like the following (like requested in #8)

pipeline {
    parameters {
        persistentBoolean(name: 'Boolean', defaultValue: true, description: 'A boolean parameter', successfulOnly: false)
        persistentString(name: 'String', defaultValue: 'a single line', description: 'A string parameter', successfulOnly: false)
        persistentText(name: 'Text', defaultValue: 'text\nwith\nmultiple\nlines', description: 'A text parameter', successfulOnly: false)
        persistentChoice(name: 'Choices', choices: ['red', 'green', 'blue'], description: 'A choices parameter', successfulOnly: false)
    }
    ...
    stages {
        ...
    }
}

The parameters are also supported by the declarative snippet generator.

For this feature it's needed to bump the minimal required Jenkins version to 2.164.1. The additional code is basically copied from the build-in non-persistent variants of these parameter types.

Further visible improvements (as they exist on the non-persistent parameter types):

Code improvements:

resolves #8, fixes #9, fixes #4

u3r commented 3 years ago

Can someone please have a a look at it and merge? This feature would be a fine addition to the plugin.

arungitan commented 3 years ago

thanks for merging this. when will it be available for automatic upgrade from Jenkins ? our devops say Jenkins doesn't give them the option to upgrade from 1.2 and the github release is not in .hpi format. I created an issue #13 for the same.

bkarakashev commented 3 years ago

I am trying to add this in a seed job but I am getting this error:

Processing DSL script nonprod_deploy.jenkins
ERROR: (nonprod_deploy.jenkins, line 30) No signature of method: javaposse.jobdsl.dsl.helpers.BuildParametersContext.persistentBoolean() is applicable for argument types: (java.util.LinkedHashMap) values: [[name:Boolean, defaultValue:true, description:A boolean parameter, ...]]
Finished: FAILURE

Any idea what I am doing wrong?

This is my code:

...
    parameters {
        persistentBoolean(name: 'Boolean', defaultValue: true, description: 'A boolean parameter', successfulOnly: false)
    }
...

However this works no problem: https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.helpers.BuildParametersContext.booleanParam

ro-kr commented 2 years ago

I guess this is a limitation of the Jenkins Job DSL plugin, it only supports the parameter types listed here: https://jenkinsci.github.io/job-dsl-plugin/#path/job-parameters