Omit empty objects

When using drone-cli’s version 1.3.0, the following jsonnet would produce the following yml file:
.drone.jsonnet:

local pipeline(boolean_to_check) =
  {
    kind: "pipeline",
    steps: [
      {
        name: "my-step",
        image: ""
        + (if boolean_to_check then "" else "my-image"),
      }
    ],
  };

[
  pipeline(true),
  pipeline(false)
]

.drone.yml:

---
kind: pipeline

platform:
  os: linux
  arch: amd64

steps:
- name: my-step

---
kind: pipeline

platform:
  os: linux
  arch: amd64

steps:
- name: my-step
  image: my-image

...

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:
.drone.yml:

---
kind: pipeline
steps:
- image: ""
  name: my-step
---
kind: pipeline
steps:
- image: my-image
  name: my-step

Command used: 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 [1] 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 [2]. 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.

[1] https://docs.drone.io/pipeline/scripting/jsonnet/
[2] https://docs.drone.io/server/reference/drone-jsonnet-enabled/

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.