Skip to content

Conversation

@ro-kr
Copy link

@ro-kr ro-kr commented Nov 24, 2020

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):

  • Option to trim the value of the persistent string parameter.
  • Proper rendering of HTML in the parameter description (see Highlighting text with HTML #4).

Code improvements:

  • Determination of default value for build moved into method getDefaultParameterValue() in order to separate it from the original default value used for editing the parameter definition.
  • Jelly code fixed and modernized.

resolves #8, fixes #9, fixes #4

@ro-kr ro-kr marked this pull request as ready for review November 26, 2020 16:28
@ro-kr ro-kr marked this pull request as draft November 28, 2020 21:35
- added symbol names so this plugin can be used in declarative pipelines
- bumped min Jenkins version to 2.164.1 (required for pipeline support)
- moved determination of default value for build into method getDefaultParameterValue() (separates it from default value used for editing the parameter definition)
- fixed and modernized Jelly code
- added more text translations
@ro-kr ro-kr marked this pull request as ready for review December 11, 2020 18:49
@u3r
Copy link

u3r commented Apr 7, 2021

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

@arungitan
Copy link

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
Copy link

bkarakashev commented Jun 15, 2021

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
Copy link
Author

ro-kr commented Nov 20, 2021

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

@ro-kr ro-kr deleted the declarative_pipeline_support branch November 20, 2021 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants