Ask Your Question
2

What is the method for obtaining the values of a choice parameter in a Jenkins build using the Jenkins remote API?

asked 2021-06-23 11:00:00 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-03-22 00:00:00 +0000

huitzilopochtli gravatar image

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
edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2021-06-23 11:00:00 +0000

Seen: 8 times

Last updated: Mar 22 '23