Ask Your Question

Revision history [back]

To obtain the values of a choice parameter in a Jenkins build using the Jenkins remote API, you can use the following steps:

  1. Get the details of the build using the Jenkins API by accessing the URL <Jenkins URL>/job/<jobname>/<build_number>/api/json.

  2. Parse the JSON response to extract the actions field.

  3. Inside the actions field, look for the parameters field and parse it.

  4. Find the choice parameter in the parameters field.

  5. 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