Use variables in pipelines plugin settings

Hey there!

[Drone 1.2.1]
I’ve been searching around on how to pass variables to a pipeline that uses the plugins/docker.
In fact, I would like to set the registry setting from a variable that could be reused in other pipelines.

Is there a way to do so in the .drone.yml file ?

Here is what a tried but the settings does not take the variables… no luck to make it work.
See the below repo or registry settings that I try to inflate with variables.

      environment: &default_environment

    kind: pipeline
    name: default

      - name: build:master
        image: plugins/docker
          <<: *default_environment
          repo: registry.${DOMAIN}/${DRONE_REPO,,}
            - ${DRONE_SOURCE_BRANCH/\//-}
            - ${DRONE_SOURCE_BRANCH/\//-}-${DRONE_COMMIT_SHA:0:8}
          registry: ${REGISTRY}
            from_secret: REGISTRY_USERNAME
            from_secret: REGISTRY_PASSWORD
            - master
              - tag

Thanks in advance for any advice or help!


One way to do it might be to use secrets however IMO it’s a shame that you can’t have public secrets - ie configuration that works like secrets but you can see the values

The reason your example does not work is two fold. First is that parameters are substituted before the yaml is parsed as noted in the documentation.

Parameter expressions are evaluated before the yaml is parsed. If you do not want the system to evaluate an expression it must be escaped.

And second, you can only substitute repository and build variables:

Please see the environment Reference for a list of parameters that can be used for substitution. Only parameters in this list can be used for substitution.

If you want to dynamically build yaml files you might consider enabling jsonnet [1][2] or installing the starlark scripting extension [3].


One way to do it might be to use secrets

This will not work with secrets because secrets are not interpolated.

1 Like

That’s very clear. Thanks @ashwilliams1.
I’ll probably give a go to jsonnet later.
Thx for the quick responses!