A bash script to automatically create tag on branch merge
-
Create a new branch in your repository.
-
Create a new file in the branch called “tag.sh”.
-
In the tag.sh file, add the following code:
#!/bin/bash
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
LATEST_COMMIT=$(git rev-parse HEAD)
git tag -a "$BRANCH_NAME-$LATEST_COMMIT" -m "Tag for merge to master"
-
Commit and push the tag.sh file to the branch.
-
Create a pull request to merge the branch into master.
-
Add a comment to the pull request with the following command:
@azure pipelines run --sh tag.sh
-
Merge the pull request into master.
-
The tag will be created automatically on the merge commit.