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

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:


Did you find a way ? I need to do the exact same thing as @xriser

It’s a pity that there is still almost no documentation on this and still no ternary operator for the parameter values. Duplicating steps because of no ternary operation is not a solution, it is not DRY and looks confusing.

I found this information:

but no ternary operator. We really need something like $(var == something ? one : two)

It’s a pity that there is still almost no documentation on this

I think this feature is pretty well documented:

but no ternary operator

The system only emulates shell parameter expansion [1]. Support for ternary operators would require us to emulate bash command substitution [2] which requires executing the command in a bash subshell environment and would therefore require emulating the full bash scripting language in our yaml. This is out of scope for what we want to provide and are willing to support.

If you need more advanced scripting capabilities we recommend installing the Starlark extension [3]. It was created for this exact purpose.


Did you find a way to get multiple substitution working. I need to do the exact same thing.