reconquest / atlassian-external-hooks

External Hooks plugin for Atlassian Bitbucket
https://external-hooks.reconquest.io
Other
44 stars 37 forks source link

Post-receive script with tag creation #59

Open mansandersson opened 6 years ago

mansandersson commented 6 years ago

I have a scritpt that creates a tag with an incrementing version number on each push to the master branch. It works fine when running standalone but does not work as external-hook script. I can see in the output that the tag has been created with the correct name but it does not show up in the bitbucket UI or when the repo is fetched. Any ideas on why?

#!/bin/bash

(
    while read from_ref to_ref ref_name; do
        branch=$(git rev-parse --symbolic --abbrev-ref $ref_name)
        if [ "master" = "$branch" ]; then
            GIT_DESCRIBE=`git describe --match=v[0-9]* 2>/dev/null`
            DASH_POS=`expr index "$GIT_DESCRIBE" -`
            LENGTH=`expr $DASH_POS - 2`
            NEW_VERSION=`expr ${GIT_DESCRIBE:1:$LENGTH} + 1`
            if [ "$NEW_VERSION" != "" ]; then
                git tag -a "v$NEW_VERSION" -m "v$NEW_VERSION"
                echo "Created a new tag, v$NEW_VERSION"
            fi
        fi
    done
) | tee -a /tmp/external-hooks-versiontag.log