what mostly we are doing like we have this push step at the last of the multi-stage build. (we have also the same step to tag image to clear confusion)
- id: 'push the docker image to registry'
name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/$REPO_NAME/$BRANCH_NAME:$SHORT_SHA']
we are using the GCR currently.
so when the build gets pushed to the registry it will create a formation URI-based auto variables getting set into the CI/CD.
same way in the release CI/CD trigger we have step to push the image to the Kubernetes cluster along with the environment variables.
- id: 'set docker image URI in YAML file'
name: 'ubuntu'
args: ['bash','-c','sed -i "s,DOCKER_IMAGE_NAME,gcr.io/$PROJECT_ID/$REPO_NAME/$BRANCH_NAME:$SHORT_SHA," deployment.yaml']
it replaces the YAML file values with the URI of the docker image where everything comes from the env variables and creates a formation of the docker image path. at last whole deployment.yaml file get to apply to the Kubernetes cluster.
incase if you want to hotfix or deploy with something special commit hash in that case you can overwrite the SHORT_SHA value by setting up the values to CI/CD trigger and run it.
So your build trigger will continuously building and pushing the images to the registry and whenever you want to deploy you can run the release trigger by default it will take the latest commit hash from the Git and set it to environment variables.