100-Days-Of-DevOps-Challenge-KodeKloud

Configure Git Hook

The Nautilus application development team was working on a git repository /opt/demo.git which is cloned under /usr/src/kodekloudrepos directory present on Storage server in Stratos DC. The team want to setup a hook on this repository, please find below more details:

Steps

  1. Login into storage server and move into directory

     sudo -i
     cd /usr/src/kodekloudrepos/demo
    
  2. Find the current branch and switch into master branch

     git branch
     git switch master
    
  3. Merge the feature branch

     git merge feature
    
  4. Add the script in hooks

     cp /opt/demo.git/hooks/post-update.sample /opt/demo.git/hooks/post-update
     chmod +x /opt/demo.git/hooks/post-update
    
  5. Update script to push tags

     vi /opt/demo.git/hooks/post-update
    

    Add these lines

     day=$(date +"%Y-%m-%d")
     TAG="release-$day"
    
     git tag -a $TAG -m "Released at: $day"
    
  6. Finally, push the changes

     git push
    

    It will add a new tags and push it

    We can verify using these commands:

     git fetch --tags
     git tag
    

Good to Know?

Git Hooks

Hook Types

Hook Implementation

Common Use Cases