jenkinsci / nomad-plugin

Nomad cloud plugin for Jenkins
https://plugins.jenkins.io/nomad/
MIT License
56 stars 41 forks source link

DevicePlugins, Nullpointer with vault policies, Error reporting #71

Closed knorx closed 3 years ago

knorx commented 3 years ago

I had several issues using the plugin.

  1. At first I wanted to add devices to the template so I can use for instance a GPU for a template. This patch introduces rudimentary device support being able to request a simple device and set a count. Special parameters are not supported yet.
  2. When using the plugin I had Nullpointer Exceptions stemming from the line where VaultPolicies were split as string. I was not able to understand the culprit completely as the vaultPolicies field had a default value of empty string, which should have been non-null. Anyways - I made the code more error resistant by representing Policies as List instead of a String internally, moving the split to Class initialization time and making sure that the whole Policies or Vault expression is omitted if it is empty.
  3. Another issue I had were Jobs which had errors at validation time in nomad. This situation was silently accepted since the plugin did not read the response it got from nomad on placing the job. I rewrote the request placing code to avoid duplicate code and print an error in the jenkins log containing the response by nomad as well as the request you made so it is easier to detect such situations.

Further changes:

  1. I changed the tests to check for the actual existence of fully-fledged Ressource section so the tests make also sure that the entries such as Devices or CPU are also placed in the right section. I added one test for the scenario I described above where the vaultPolicies is null. Since it is now possible to cope with that situation I also removed the empty string in that fields default.
  2. I added help texts for vaultPolicies and constraints.