When using drone-cli’s version 1.3.0, the following jsonnet would produce the following yml file:
local pipeline(boolean_to_check) =
+ (if boolean_to_check then "" else "my-image"),
- name: my-step
- name: my-step
When using newer versions, v1.5.0 for instance, and the same .drone.jsonnet from previously the output would be different, keeping all empty values like so:
- image: ""
- image: my-image
go run . jsonnet --stream --format.
I was in GitHub - harness/drone-cli: Command Line Tools for Drone CI switching tags.
Is it possible to have the old behavior somehow? (ommit empty objects)
PS.: As far as I’m aware this occurs with strings and objects, haven’t tested other things.
This is the default behavior of the yaml serializer we now use, so unfortunately no, we cannot revert this behavior. There is no harm in an empty string. The zero value of a string in Go is an empty string. This means, as far as our parser is concerned, there is no difference between omitting the attribute (zero value) and setting the attribute to an empty string (also a zero value).
If the concern is aesthetic, keep in mind that Drone natively supports jsonnet  which means you no longer need to convert the file and commit to your repository. You would need to enable a flag in your Drone server . Then you would need to update your repository settings, from the repository settings screen in the user interface, to use the jsonnet file instead of a yaml file.
Hi Brad, thanks for the response.
I’m aware of both points, however about using the jsonnet, we use
when.paths in our config, so we can not use the jsonnet directly. Execute all convert plugins every time. by captncraig · Pull Request #2994 · harness/drone · GitHub.
About leaving the empty values, I’m also aware of that, it’s just that is not as human readable as removing/omitting them. Most of my coworkers use drone.yml, so from time to time, they prefer to read the yml file and them seek out how to update jsonnet accordingly.