Docker docker image and the push in another step

Hey,

I have a small question that could speed up pipelines for me.
Now i build a Docker image to see if it works because i want to test that on all branches.
But on main i want to build and push the docker image. But what is happening now is that the image is build 2 times and on of them is pushed.

Is there a easy way to use the build docker image from a step and then later push it?

What is have now:

kind: pipeline
name: Backend Node js
type: docker

steps:
- name: test node 12
  image: node:12-alpine
  {{ A LOT OF STUFF YOU DO NOT NEED/WANT TO SEE }}

- name: docker build
  image: plugins/docker
  settings:
    dry_run: True
    tags: latest
    repo: registry.sliceofbits.com/ipsen2backend

{{ Some more test steps }}

- name: docker build and push
  image: plugins/docker
  settings:
    cache_from: registry.sliceofbits.com/ipsen2backend:latest
    username:
      from_secret: username
    password:
      from_secret: password
    repo: registry.sliceofbits.com/ipsen2backend
    registry: registry.sliceofbits.com/
    tags: latest
  when:
    branch:
      - master
    event:
      - push
  depends_on:
    - test node 12
    - docker build

{{ SOME WEBHOOKS AND CODECOV UPLOAD }}

Thank you in advance :heart:

Hey, Yes you should be able to run docker commands in different steps, in first step you can run docker build and in next step you can run docker push. Please refer earlier post for information

Let us if you have any questions.

-Harness Support