Add REST List Parameter plugin support with test

Change-Id: I92daf7a24257b2f570f27040accae4b1dcb54e33
This commit is contained in:
Robert Rounsaville
2025-08-05 17:11:25 -04:00
parent 56f2a81315
commit 36ae01acb5
9 changed files with 207 additions and 0 deletions

View File

@@ -649,6 +649,63 @@ def svn_tags_param(registry, xml_parent, data):
helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True)
def rest_list_param(registry, xml_parent, data):
"""yaml: rest-list
REST List Parameter
Requires the Jenkins :jenkins-plugins:`REST List Parameter
<rest-list-parameter>`.
:arg str name: the name of the parameter
:arg str rest-endpoint: the url of the REST API endpoint
:arg str credentials-id: Credentials ID to use for authentication
(default '')
:arg str filter: the regular expression to filter the already parsed values (default '.*')
:arg str mime-type: the expected response type of the endpoint
:arg str value-expression: the Json-Path or xPath used to parse values
:arg str display-expression: the Json-Path or xPath used to dictate how the values get displayed
:arg int cache-time: the time in minutes to cache API response
:arg str default-value: the per-selected default value (must be within the received value list)
(default '')
:arg str value-order: the sort order of the values ('ASC' || 'DSC' || 'NONE') (default: 'NONE')
Example::
parameters:
- rest-list:
name: REST_VALUE
description: ''
rest-endpoint: 'http://test.lan'
credentials-id: ''
mime-type: 'APPLICATION_JSON'
value-expression: '$.*'
display-expression: '$'
cache-time: 10
default-value: ''
filter: '.*'
value-order: 'ASC'
"""
pdef = base_param(
registry,
xml_parent,
data,
False,
"io.jenkins.plugins.restlistparam.RestListParameterDefinition",
)
mapping = [
("rest-endpoint", "restEndpoint", ""),
("mime-type", "mimeType", ""),
("credentials-id", "credentialId", ""),
("value-expression", "valueExpression", "$.*"),
("display-expression", "displayExpression", "$"),
("cache-time", "cacheTime", 0),
("default-value", "defaultValue", ""),
("filter", "filter", ".*"),
("value-order", "valueOrder", "NONE"),
]
helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True)
def dynamic_choice_param(registry, xml_parent, data):
"""yaml: dynamic-choice
Dynamic Choice Parameter

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<io.jenkins.plugins.restlistparam.RestListParameterDefinition>
<name>api_environments</name>
<description>Select an environment from the API registry</description>
<restEndpoint>https://api.company.com/v1/environments</restEndpoint>
<mimeType>APPLICATION_JSON</mimeType>
<credentialId>api-service-token</credentialId>
<valueExpression>$.environments[*].name</valueExpression>
<displayExpression>$.environments[*].displayName</displayExpression>
<cacheTime>15</cacheTime>
<defaultValue>production</defaultValue>
<filter>^(dev|staging|prod).*</filter>
<valueOrder>ASC</valueOrder>
</io.jenkins.plugins.restlistparam.RestListParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
</project>

View File

@@ -0,0 +1,13 @@
parameters:
- rest-list:
name: api_environments
description: Select an environment from the API registry
rest-endpoint: https://api.company.com/v1/environments
credentials-id: api-service-token
mime-type: APPLICATION_JSON
value-expression: $.environments[*].name
display-expression: $.environments[*].displayName
cache-time: 15
default-value: production
filter: ^(dev|staging|prod).*
value-order: ASC

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<io.jenkins.plugins.restlistparam.RestListParameterDefinition>
<name>api_values</name>
<description/>
<restEndpoint>https://api.example.com/values</restEndpoint>
<mimeType>APPLICATION_JSON</mimeType>
<credentialId/>
<valueExpression>$.*</valueExpression>
<displayExpression>$</displayExpression>
<cacheTime>0</cacheTime>
<defaultValue/>
<filter>.*</filter>
<valueOrder>NONE</valueOrder>
</io.jenkins.plugins.restlistparam.RestListParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
</project>

View File

@@ -0,0 +1,5 @@
parameters:
- rest-list:
name: api_values
rest-endpoint: https://api.example.com/values
mime-type: APPLICATION_JSON

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</description>
<keepDependencies>false</keepDependencies>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<concurrentBuild>false</concurrentBuild>
<canRoam>true</canRoam>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<io.jenkins.plugins.restlistparam.RestListParameterDefinition>
<name>api_values</name>
<description/>
<restEndpoint>https://api.example.com/values</restEndpoint>
<mimeType>APPLICATION_JSON</mimeType>
<credentialId/>
<valueExpression>$.*</valueExpression>
<displayExpression>$</displayExpression>
<cacheTime>0</cacheTime>
<defaultValue/>
<filter>.*</filter>
<valueOrder>NONE</valueOrder>
</io.jenkins.plugins.restlistparam.RestListParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
<scm class="hudson.scm.NullSCM"/>
<builders/>
<publishers/>
<buildWrappers/>
</project>

View File

@@ -0,0 +1,7 @@
- job:
name: rest-list-minimal-job
parameters:
- rest-list:
name: api_values
rest-endpoint: https://api.example.com/values
mime-type: APPLICATION_JSON

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</description>
<keepDependencies>false</keepDependencies>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<concurrentBuild>false</concurrentBuild>
<canRoam>true</canRoam>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<io.jenkins.plugins.restlistparam.RestListParameterDefinition>
<name>api_environments</name>
<description>Select an environment from the API registry</description>
<restEndpoint>https://api.company.com/v1/environments</restEndpoint>
<mimeType>APPLICATION_JSON</mimeType>
<credentialId>api-service-token</credentialId>
<valueExpression>$.environments[*].name</valueExpression>
<displayExpression>$.environments[*].displayName</displayExpression>
<cacheTime>15</cacheTime>
<defaultValue>production</defaultValue>
<filter>^(dev|staging|prod).*</filter>
<valueOrder>ASC</valueOrder>
</io.jenkins.plugins.restlistparam.RestListParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
<scm class="hudson.scm.NullSCM"/>
<builders/>
<publishers/>
<buildWrappers/>
</project>

View File

@@ -0,0 +1,15 @@
- job:
name: rest-list-full-job
parameters:
- rest-list:
name: api_environments
description: Select an environment from the API registry
rest-endpoint: https://api.company.com/v1/environments
credentials-id: api-service-token
mime-type: APPLICATION_JSON
value-expression: $.environments[*].name
display-expression: $.environments[*].displayName
cache-time: 15
default-value: production
filter: ^(dev|staging|prod).*
value-order: ASC