To obtain the values of a choice parameter in a Jenkins build using the Jenkins remote API, you can use the following steps:
Get the details of the build using the Jenkins API by accessing the URL <Jenkins URL>/job/<jobname>/<build_number>/api/json
.
Parse the JSON response to extract the actions
field.
Inside the actions
field, look for the parameters
field and parse it.
Find the choice parameter in the parameters
field.
Extract the values of the choice parameter.
Here's an example code snippet in Python to help clarify the steps:
import json
import requests
jenkins_url = "http://<Jenkins URL>"
job_name = "<jobname>"
build_number = "<build_number>"
build_details_api = f"{jenkins_url}/job/{job_name}/{build_number}/api/json"
response = requests.get(build_details_api)
build_details = json.loads(response.text)
for action in build_details["actions"]:
if "parameters" in action:
params = action["parameters"]
for param in params:
if param["name"] == "<choice_parameter_name>":
choice_values = param["value"]
# Do something with the choice values
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-06-23 11:00:00 +0000
Seen: 8 times
Last updated: Mar 22 '23
How can I set up Gunicorn with a Django Project?
Looking for a Python Module that finds Tags for a Text describing its Content
Need a Function in Python to remove entries less than 2 digits from an Array
How can I convert a Document in Python?
How can I program a Loop in Python?
How can I enable Python Code Highlighting in Askbot?