Some context: I am in a git enterprise environment and there is a git repo where I pull the whole code, gulp build it and then copy the distribution to another repo, where I push it to remote.
I have automated all that in a bash script and whenever I execute sh gittogulp.sh
it does that flawlessly. But when I use a cronjob to do that, it fails to pull new content from git and makes gulp builds from content that is already there.
I want to know, how can I pull from a git repo without manually triggering the script. Webhooks is not an option for me. :(
gittogulp.sh
is:
#!/bin/bash
cd ~/mainrepo
git checkout dev
git fetch
echo "Pulling latest code from git repo"
git pull
for commitid in $(git log --format="%h" -n 10)
do
git checkout dev
echo "git reset hard"
git fetch --all
git reset --hard origin/dev
echo "Checkout commit id: ""$commitid"
echo git checkout "$commitid"
git checkout "$commitid"
echo "Installing dependencies"
npm install
echo "Gulpifying the code"
gulp dev
basefolder="/root/mainrepo/manifests"
basedestfolder="/root/outputrepo/dev"
if [ -d "$basefolder" ]; then
versionrepo=`cat "$basefolder"/version.txt`
echo "Version in repo: ""$versionrepo"
destfolder="$basedestfolder""/""$commitid"
if [ -d "$destfolder" ]; then
echo "Latest outputs are already in place"
break
else
echo "copying latest output to ""$destfolder"
mkdir "$destfolder"
cp -r "$basefolder" "$destfolder"
zipname="$versionrepo""_""$commitid"".zip"
zipdestpath="$basedestfolder""/""$zipname"
echo "Making new zip from latest commit"
echo zip -r "$zipdestpath" "$destfolder"
zip -r "$zipdestpath" "$destfolder"
fi
else
echo "$basefolder"" : folder doesn't exist, exiting"
fi
done
cd ~/outputrepo
git pull
git add .
git commit -m "adding new zip"
git push