Create a custom tag automatically

create tag when commit or merge_request happens to branch,
we are using these CI now for build and push docker images to my docker repo, when we create tag it will trigger to run these pipeline.

  • docker build -t $DOCKER_REGISTRY/$DOCKER_IMAGE:$CI_COMMIT_SHA .
  • docker push $DOCKER_REGISTRY/$DOCKER_IMAGE:$CI_COMMIT_SHA,

Now i want to automate it when commit or merge request in the branch it create tag and trigger the pipeline,

Please help on this,thanks in advance.