Variable substitution only replaces the first encountered

Variable substitution only replaces the first encountered instance of substring.

For example:

  tags:
    - ${DRONE_COMMIT_BRANCH/\//-}

am using a branch “feature/test/dashes” and am getting the following:

feature-test/dashes" is not a valid repository/tag

So it’s replaced the first instance of “/”, but not the second one. I would have expected it to replace all the instances of “/” in my branch name.

The reason is because a single / replaces the first match, where as // replaces all matches. If you want to replace all matches you can adjust the syntax slightly:

${stringZ//\//-}

We have a unit test that verifies this functionality:

Thank you, that worked!