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

fix(jenkins): don't npe on dynamic choice parameters #502

Merged
merged 2 commits into from
Sep 4, 2019

Conversation

emjburns
Copy link
Contributor

@emjburns emjburns commented Sep 4, 2019

In Jenkins, you can have a "dynamic choice parameter". This means that you can write a script to generate all the dropdown choices for a parameter. It seems like this script is only run when you hit "build with parameters". When you query for the job config (https://jenkins-controller/job/job-name//api/xml?exclude=/*/action&exclude=/*/build&exclude=/*/property[not(parameterDefinition)]) you actually get no choices. Better yet, instead of an empty list, choices is null!

This PR makes adds a null check to parameterDefinition.choices so that if it's null we just don't validate. Right now we throw an NPE.

@emjburns emjburns requested a review from asher September 4, 2019 20:57
if (matchingParam != null &&
parameterDefinition.type == 'ChoiceParameterDefinition' &&
parameterDefinition.choices != null &&
!parameterDefinition.choices.contains(matchingParam)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. For long conditions such as this, I like to break them out into a separate (static whenever possible) method.
  2. Test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like since this is already a part of a small static method i'll just add a test for that method. sound ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds legit, I didn't notice how small this method was already.

@emjburns emjburns merged commit 3aecf2f into spinnaker:master Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants