Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-57125] Trim the value and request parameter options #112

Merged
merged 2 commits into from
Apr 26, 2024

Conversation

therealsujitk
Copy link
Contributor

Relevant Issues

The reason for this issue is because the plugin's function splits the valueStr by commas (,) and does not account for possible spaces between them.

String valueStr = "option1, option2, option3, option4";
String[] values = valueStr.split(); // ["option1", " option2", " option3", " option4"]

Notice the space prefix in the strings. Because of this when a parameter is passed using /buildWithParameters without the space prefix, it gets ignored.

[POST] /buildWithParameters?parameter=option1&parameter=option2

Here option1 gets accepted, however option2 gets ignored. To solve this I've split the valueStr by commas and taken spaces into consideration. Additionally I have also trimmed the values that are passed by the user.

Workaround

The temporary solution is to remove all the spaces from the options string in the job configuration, if that isn't possible you can pass the value to the endpoint along with the space (%20) as shown below.

[POST] /buildWithParameters?parameter=option1&parameter=%20option2

Testing done

  1. Create a project with an Extend Choice Parameter of type Multi Select. Set the value as a string separated by commas and be sure to include spaces.
    Screenshot 2024-04-25 at 16 15 36
  2. To test this I was initially getting a No valid crumb was included error while trying to make a POST request, so I disabled CSRF protection to get around this.
  3. Trigger a build from the API endpoint with this key, I've done this using the curl command.
    curl http://localhost:5000/jenkins/job/Test%20Pipeline/buildWithParameters --data parameter=option1 --data parameter=option2

Submitter checklist

Preview Give feedback

@therealsujitk therealsujitk requested a review from a team as a code owner April 25, 2024 10:54
@chonton chonton added java Pull requests that update Java code fix Pull request to fix an issue labels Apr 26, 2024
@chonton chonton merged commit 5697b32 into jenkinsci:main Apr 26, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Pull request to fix an issue java Pull requests that update Java code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants