I am using drone CI with the docker plugin and I would like to create an image tag using the commit, the branch name and the tag if any of those exist in the event that triggered the pipeline. How would I do that?
I've tried using defaults to avoid the build crashing because "foo/bar:" isn't a valid tag but this is not an ideal solution and for the branch name I need to replace a part of the string and I cant find a way to do both.
So, how would you apply a tag only if the env variable exists?
You can use the when to make sure the env variable is only used when it exists:
- name: docker_build_tag
image: plugins/docker
when:
event: tag
settings:
username:
from_secret: docker_hub_username
password:
from_secret: docker_hub_token
tags: ${DRONE_TAG}