Using python to build a jenkins job: how to pass checkbox values

52 Views Asked by At
jenkins_server = jenkins.Jenkins(project_path, username="moyemoye", password=password, timeout=120)
parameters = {
    'IMG_PATH': "IMG_PATH",
    'vcpu': "2",
    'Topo_Traffic_Type': "imix,1518/1400",
    'RUN_CEF_SUITE_FEATURE_LIST': "all",
    'clean_reload': True,
}
jenkins_server.build_job(f"{project_name}", parameters=parameters, token=password)

RUN_CEF_SUITE_FEATURE_LIST and Topo_Traffic_Type both are of type "Basic Parameter Types" with parameter type as CheckBoxes.

When I build the project using the code above, RUN_CEF_SUITE_FEATURE_LIST fills in properly (maybe because I need to check only one box out of all options) but Topo_Traffic_Type stays empty and the project fails. Any idea on whats wrong?

The documentation: enter image description here

EDIT: Tried the below but still does not work:

'Topo_Traffic_Type': ["imix", "1518/1400"]
'Topo_Traffic_Type': "imix,1518/1400"
'Topo_Traffic_Type': [{"imix": True}, {"1518/1400": True}]
'Topo_Traffic_Type': {"imix": True, "1518/1400": True},
1

There are 1 best solutions below

0
Noam Helmer On

The Extended Choice Parameter plugin is indeed lacking relevant usage documentation when it comes to using it in API calls and many options need to be figured by exploring the source code.

In your case the solution is simple but tricky, for each checkbox value you want to turn on you will need to pass the parameter with the relevant value, so if you want to turn on 2 checkboxes, you will need to pass the parameter twice each time with a different value. The plugin will then accumulate all values together.

In an API call it will look like:

https://<JENKINS_URL>/job/<JOB_NAME>/buildWithParameters?token=token&<PARAM_NAME>=<VALUE1>&<PARAM_NAME>=<VALUE2>

In your python code it will look like:

parameters = {
    'IMG_PATH': "IMG_PATH",
    'vcpu': "2",
    'Topo_Traffic_Type': "imix",
    'Topo_Traffic_Type': "1518/1400",
    'RUN_CEF_SUITE_FEATURE_LIST': "all",
    'clean_reload': True,
}

For any additional check box selection you want to add for Topo_Traffic_Type you will need to pass the parameter again with the corresponding value. All passed values will be then available via a single value in the pipeline (or freestyle) defined parameter.
It is a bit confusing, and I'm not sure why its implemented like this, but it should solve your issue.