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.

    variables:
      environment: &default_environment
        REGISTRY: registry.mydomain.com
        DOMAIN: mydomain.com

    kind: pipeline
    name: default

    steps:
      - name: build:master
        image: plugins/docker
        environment:
          <<: *default_environment
        settings:
          repo: registry.${DOMAIN}/${DRONE_REPO,,}
          tags:
            - ${DRONE_SOURCE_BRANCH/\//-}
            - ${DRONE_SOURCE_BRANCH/\//-}-${DRONE_COMMIT_SHA:0:8}
          registry: ${REGISTRY}
          username:
            from_secret: REGISTRY_USERNAME
          password:
            from_secret: REGISTRY_PASSWORD
        when:
          branch:
            - master
          event:
            exclude:
              - tag

Thanks in advance for any advice or help!

Antoine

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

http://discuss.harness.io/t/would-it-be-an-idea-to-have-public-secrets/6963

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].

[1] Jsonnet | Drone
[2] DRONE_JSONNET_ENABLED | Drone
[3] Starlark | Drone

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!