Git hook error: release tag was not created from the master branch - Day 34

I am doing 100 days Devops training and I am stuck on Day 34: Git Hook

Steps I am following

  1. vi /opt/apps.git/hooks/post-update

      #!/usr/bin/bash
       for ref in "$@"; 
       do
           if [ "$ref" = "refs/heads/master" ]; 
           then
               TAG_NAME="release-$(TZ="America/Chicago" date +%F)"
               git tag -a "$TAG_NAME" -m "Automated release for TODAY" "$ref"
               echo "Remote: Tag created $TAG_NAME"
           fi
       done
       exec git update-server-info
    
  2. cd /usr/src/kodekloudrepos/apps/

  3. git checkout master

  4. git merge feature

  5. git push

  6. Successfully verified created Tag in master branch name.

Everything looks good but I am not able to figure it out what might be the problem! see if anyone is able to come up with the solution… Thank you :grinning:

I am doing 100 days Devops training and I am stuck on Day 34: Git Hook

Steps I am following

  1. vi /opt/apps.git/hooks/post-update

      #!/usr/bin/bash
       for ref in "$@"; 
       do
           if [ "$ref" = "refs/heads/master" ]; 
           then
               TAG_NAME="release-$(TZ="America/Chicago" date +%F)"
               git tag -a "$TAG_NAME" -m "Automated release for TODAY" "$ref"
               echo "Remote: Tag created $TAG_NAME"
           fi
       done
       exec git update-server-info
    
  2. cd /usr/src/kodekloudrepos/apps/

  3. git checkout master

  4. git merge feature

  5. git push

  6. Successfully verified new created Tag in master branch name.

Everything looks good but I am not able to figure it out what might be the problem! see if anyone is able to come up with the solution… Thank you :grinning:

I Tried other people’s solution too, which for them it was working fine, but for me it is constantly giving me same error message.

Creating a light-weight tag should work instead of the annotated tag, check the difference between them here.
I’ve seen quite a few users raise similar issue, I guess it is supposed to be specified in the question.

In short creating a tag like below should work.
git tag "$TAG_NAME"

1 Like

Hi Srikanth, Amazing man!!! IT Worked

Party’s on me, where are you located brother, I tried with git tag “$TAG_NAME”, and it worked superb.

1 Like
#!/bin/bash

echo "Starting post-update hook"

for refname in "$@"; do
    echo "Processing ref: $refname"
    if [[ "$refname" == "refs/heads/master" ]]; then
        echo "Creating tag for release"
        TODAY=$(date +%F)
        git tag "release-$TODAY" -m "Automated release tag for $TODAY"
    else
        echo "No action for ref: $refname"
    fi
done
echo "Post-update hook completed"
exit 0

Hello guys, i tried with this script and not working.
Previously i tried with git tag -a and later i found this post and try again with git tag “$MSG” but still not working for me.

#!/usr/bin/bash
        for ref in "$@"; 
        do
            if [ "$ref" = "refs/heads/master" ]; 
            then
                ### remove this if you feel = TZ="America/Chicago"
                TAG_NAME="release-$(TZ="America/Chicago" date +%F)" 
                git tag "$TAG_NAME"
                echo "Remote: Tag created $TAG_NAME"
            fi
        done
        exec git update-server-info

Try not to give too much values to git tag, keep it simple something like: git tag “$TAG_NAME”

We’re about to update the task, in the next day or so. But one thing I’d say to remove from your script: “git update-server-info” should be unneeded, might be harmful in this case.

1 Like