I am in a git enterprise environment and there is a git repo where I pull the whole code, build it using gulp.js 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.js 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:

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)
    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
    if [ -d "$basefolder" ]; then

        versionrepo=`cat "$basefolder"/version.txt`
        echo "Version in repo: ""$versionrepo"

        if [ -d "$destfolder" ]; then
            echo "Latest outputs are already in place"
            echo "copying latest output to ""$destfolder"
            mkdir "$destfolder"
            cp -r "$basefolder" "$destfolder"
            echo "Making new zip from latest commit"
            echo zip -r "$zipdestpath" "$destfolder"
            zip -r "$zipdestpath" "$destfolder"

        echo "$basefolder"" : folder doesn't exist, exiting"

cd ~/outputrepo
git pull
git add .
git commit -m "adding new zip"
git push
  • What exactly is in the script? Have you kept the error output when run via cron, like in askubuntu.com/a/604036/158442? If not, do so and add the output to the question. – muru Feb 17 '18 at 9:01
  • I have added the script now. No, i have not added the logs, i didn't know that. i'll do it now and paste it here. – naqushab Feb 17 '18 at 9:47

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.