Gitlab-ci different variable depending if stage was skipped or executed?

Hi fellow Gitlabers,

I have a pipeline that builds and deploys docker image. As a best practice I tag docker Image using ${CI_COMMIT_SHORT_SHA}. I also only build image only if changes to dockerfile or App.js happen:

Build job:

...  skipped boring part
- docker push ${REPO}:${IMAGE_TAG}
      - Dockerfile
      - app.js

Deploy job:
- terraform apply -auto-approve -var "app_image=${REPO}:${IMAGE_TAG}"

The problem is that sometimes I might want to deploy the image without building it again. In this case it would be good to use previous commit sha. Is it possible to do that? Or am I thinking wrong about something?