Bug?: Variable Expansion Requires Quotes In Some Situations

I just spent a couple of hours troubleshooting why this .drone.yml would not compile:

---
kind: pipeline
name: build

steps:
  # Make sure image builds
  - name: build
    image: katharostech/drone-kaniko

trigger:
  ref:
    exclude:
      - refs/tags/v*
  branch:
    exclude:
      - feature/*

---
kind: pipeline
name: release

steps:
  # Release image to Docker Hub
  - name: release
    image: katharostech/drone-kaniko
    settings:
      repo: katharostech/mysql-backup
      tags: ${DRONE_TAG}, latest
      username:
        from_secret: docker-username
      password:
        from_secret: docker-password
    when:
      ref:
        - refs/tags/v*

trigger:
  event:
    - tag
  ref:
    - refs/tags/v*

It would fail with the message:

build: yaml: line 9: did not find expected node content

It turns out that the tags setting needed to have quotes around it like so

...
steps:
  # Release image to Docker Hub
  - name: release
    image: katharostech/drone-kaniko
    settings:
      repo: katharostech/mysql-backup
      tags: "${DRONE_TAG}, latest"
      username:
        from_secret: docker-username
      password:
        from_secret: docker-password
    when:
      ref:
        - refs/tags/v*
...

Quotes are not usually needed in yaml for anything that is apparently not any other type, but for some reason Drone has a problem in the case of variable expansion. Additionally, it doesn’t have any problems if you just use ${DRONE_TAG} as the tags value. The only time it has problems is when you combine variable expansion with other text in the same setting.

Also, the bug is somewhat elusive because it only seems to happen when there are multiple pipelines as well ( I think ). It took me so long to find what was causing it because there would be strange cases where it would work.

I’m not sure if this counts as a bug or not, but either way this could be good for somebody else to know.

The yaml file is parsed after string substitution. When you use string substitution you must therefore ensure you are generating a valid yaml once the values have been substituted, including situations where the value may be an empty string. This means sometimes you may need to quote the string.

Example with quoted string:

tags: [ "${DRONE_TAG}", "latest" ]

Example using modified yaml structure to avoid quoting:

tags:
- ${DRONE_TAG}
- latest

As an aside, note that tags is meant to be an array and in your example you passed the array value as a string literal.

1 Like

Oh, as an array that makes more sense. I didn’t realize it was an array. Thank you for the explanation.