Tag Docker image with latest only on certain branch

Hi,

I am trying to achieve the following:

  1. On push to master branch, build docker image and tag with latest, abbreviated commit hash and build number.
  2. On push to non-master branch, build docker image and tag with abbreviated commit hash and build number.

Is there a way to combine both of those operations into a single pipeline step? E.g

docker:
    image: plugins/docker
    repo: my-repo
    tags:
      - latest
      - ${DRONE_BUILD_NUMBER}
      - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:8}
    when:
      event: push
      branch: [master, qa]

The issue with the above is that it will tag the image with latest even if the build is for a qa branch. I can create two pipeline steps, one for master and one for qa, but was wondering if there’s a simpler way.

This would need to be split into two separate steps. If you are concerned about code-duplication in the yaml, you can take advantage of yaml anchors. There is a good write-up about it at https://medium.com/@kinghuang/docker-compose-anchors-aliases-extensions-a1e4105d70bd

Thanks @bradrydzewski! I’ll give that a look.