diff --git a/jenkins_jobs/modules/parameters.py b/jenkins_jobs/modules/parameters.py index b39e66c2b..5a4f8603c 100644 --- a/jenkins_jobs/modules/parameters.py +++ b/jenkins_jobs/modules/parameters.py @@ -783,6 +783,35 @@ def hidden_param(parser, xml_parent, data): 'com.wangyin.parameter.WHideParameterDefinition') +def random_string_param(registry, xml_parent, data): + """yaml: random-string + This parameter generates a random string and passes it to the + build, preventing Jenkins from combining queued builds. + Requires the Jenkins :jenkins-wiki:`Random String Parameter Plugin + `. + + :arg str name: Name of the parameter + :arg str description: Description of the parameter (default '') + :arg str failed-validation-message: Failure message to display for invalid + input (default '') + + Example: + + .. literalinclude:: + /../../tests/parameters/fixtures/random-string-param001.yaml + :language: yaml + """ + pdef = XML.SubElement(xml_parent, + 'hudson.plugins.random__string__parameter.' + 'RandomStringParameterDefinition') + if 'name' not in data: + raise JenkinsJobsException('random-string must have a name parameter.') + XML.SubElement(pdef, 'name').text = data['name'] + XML.SubElement(pdef, 'description').text = data.get('description', '') + XML.SubElement(pdef, 'failedValidationMessage').text = data.get( + 'failed-validation-message', '') + + class Parameters(jenkins_jobs.modules.base.Base): sequence = 21 diff --git a/tests/parameters/fixtures/random-string-param001.xml b/tests/parameters/fixtures/random-string-param001.xml new file mode 100644 index 000000000..bef9e3627 --- /dev/null +++ b/tests/parameters/fixtures/random-string-param001.xml @@ -0,0 +1,14 @@ + + + + + + + job-string + A random string passed to the job + Your input string is invalid + + + + + diff --git a/tests/parameters/fixtures/random-string-param001.yaml b/tests/parameters/fixtures/random-string-param001.yaml new file mode 100644 index 000000000..f609b4523 --- /dev/null +++ b/tests/parameters/fixtures/random-string-param001.yaml @@ -0,0 +1,5 @@ +parameters: + - random-string: + name: job-string + description: "A random string passed to the job" + failed-validation-message: "Your input string is invalid"