Multiple substitution


Greetings Friends,

I am having a small issue, I am upgrading from Drone 0.5 to drone 0.8 and I cannot do this anymore:
- “BRANCH_ENV=${DRONE_BRANCH|s/develop/dev/|s/master/prod/|s/^release.+/qa/”

Because I get a “bad substitution error”

While checking at the substitution documentation I have seen an example like this:

But I am looking for a “multiple substitution solution” I have tried doing something like this and it did not help:

Does any of you have any idea how it could be achieved?


you need to use $${DRONE_BRANCH. See this section of the docs for more details


Hello Brad,

Thanks for the swift reply! My other problem is if I want to do the same thing for a “tag section” in for a docker section

Here is my old (works with 0.5)

    repo: "${DRONE_REPO_LC}"
    dockerfile: Dockerfile
      - "BRANCH_ENV=${DRONE_BRANCH|s/develop/dev/|s/master/prod/|s/^release.+/qa/}"
      - "${DRONE_BRANCH|s/develop/dev/|s/master/prod/|s/^release.+/qa/}"
      branch: [master, develop, release/*]

I am looking for a similar solution. $${DRONE_BRANCH should work in the environment section but it will not work in the TAG section. I only want 3 specific tags + number

Is it not possible to work with the ${param/old/new} like mentioned in the documentation?


That syntax is not supported in the tag section. The docker tag field is a Go string literal (not a bash string) which means it will not evaluate your bash expression. The same is true of the environment section. Please see, specifically the last example which explains this further.

Drone does try to emulate bash expressions, but has limited support. You can see supported syntax of emulated expressions here:


I have read the documentation about variable substitution… which is the source of my question.

By reading the documentation found here they show an example of a single substitution variable.


But I ws wondering if it was possible to do something like


If old1 replace with new1 (if branch == master tag must be prod)
if old2 replace with new2 (if branch == develop tag must be dev)
if old3 replace with new3 (if branch == release/* tag must be qa)

Or something similar with drone support? It needs to be done in the tag section…

Thanks a lot for your reply once again!


I think the first step if to create a substitution string that works from a posix-compliant shell. The substitution commands that you provided returns an error on my shell:

$ export DRONE_BRANCH=master
$ echo ${DRONE_BRANCH|s/develop/dev/|s/master/prod/|s/^release.+/qa/}
-bash: ${DRONE_BRANCH|s/develop/dev/|s/master/prod/|s/^release.+/qa/}: bad substitution

If you have a posix-compliant expression, and it does not work in Drone, we can work on supporting it in our emulation code in a future release.

You can also split these into multiple steps (below). If you are concerned with keeping things DRY you can use YAML anchors.

    repo: octocat/hello-world
    tags: master
      branch: master

    repo: octocat/hello-world
    tags: dev
      branch: develop

    repo: octocat/hello-world
    tags: ${DRONE_BRANCH:8}
      branch: release/*


Hahah, yeah I was trying to avoid something like that :slight_smile:

Thanks a lot for your help!


How to combine toLower with remove substring ?
my DRONE_COMMIT_BRANCH=feature/XP-9999
I need create docker tag: “xp-9999”

so I need to combine this two substitutions: