Can I use environment variable as a value for property in the step item

It it possible to use environment variable as a value for image?
Why do I need this?

  1. I don’t want duplicate code
  2. I want to change image name in one place instead of going to each pipeline and change it everywhere

For example:

  DOCKER_IMAGE_CACHE_NAME: "drillster/[email protected]:some-sha"

- name: Restore cache

The error I receive is Error response from daemon: invalid reference format.

None of these worked:


Can I use environment variable as a value for property in the step item

Only variables in this list can be used as substitution parameters in step attributes. User-defined values are not supported. When Drone injects variables in the yaml, they are injected before the yaml is parsed (using something similar to find / replace). In your example, it would require injecting variables after the yaml is parsed which is not possible based on the current design.

This is actually supported using yaml features called anchors and aliases. These features are native to the yaml language; they are not unique to Drone. See the following document (or search google):

Here is an example:

  image: &image "alpine"

- name: foo
  image: *image

- name: bar
  image: *image

Paste the above yaml into the below website, and you can see how it works:

Also note that Drone supports yaml alternatives, including Starlark and Jsonnet. If your goal is to keep your configuration DRY and anchors and aliases are insufficient, Starlark and Jsonnet are the recommended solution.

1 Like