agent: |
t3XgW1FMIniUDsbFGKDeGet the input parameters of a Jenkins pipeline
Get the input parameters of a Jenkins pipeline
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
Python script to get the parameter definitions for the Jenkins pipeline 'taskservice' considering 'property' is an array
inputs
outputs
import requests
# Get environment variables
jenkins_username = getEnvVar('JENKINS_USERNAME')
jenkins_api_token = getEnvVar('JENKINS_API_TOKEN')
jenkins_url = getEnvVar('JENKINS_URL')
# Jenkins API endpoint to get parameter definitions
url = f'{jenkins_url}/job/{pipeline_name}/api/json?tree=property[parameterDefinitions[name,type,defaultParameterValue[value]]]'
# Make the request
response = requests.get(url, auth=(jenkins_username, jenkins_api_token))
# Check if the request was successful
if response.status_code == 200:
data = response.json()
parameter_definitions = []
for prop in data.get('property', []):
if 'parameterDefinitions' in prop:
parameter_definitions.extend(prop['parameterDefinitions'])
parameters = [{
'name': param['name'],
'type': param['type'],
'default': param['defaultParameterValue']['value'] if 'defaultParameterValue' in param else None
} for param in parameter_definitions]
print('Pipeline Name:', pipeline_name)
print('Parameter Definitions:', parameters)
else:
parameters = []
print('Failed to fetch parameter definitions:', response.status_code)
default_values = {}
for param in parameter_definitions:
default_values[param['name']] = param['default']
copied