Git Pull and then Push via Cron in Ubuntu

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
0
down vote

favorite












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:



#!/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









share|improve this question























  • 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 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 at 9:47














up vote
0
down vote

favorite












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:



#!/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









share|improve this question























  • 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 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 at 9:47












up vote
0
down vote

favorite









up vote
0
down vote

favorite











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:



#!/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









share|improve this question















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:



#!/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






bash scripts cron git






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 17 at 9:46

























asked Feb 17 at 8:56









naqushab

1034




1034











  • 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 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 at 9:47
















  • 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 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 at 9:47















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 at 9:01




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 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 at 9:47




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 at 9:47















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1007010%2fgit-pull-and-then-push-via-cron-in-ubuntu%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1007010%2fgit-pull-and-then-push-via-cron-in-ubuntu%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Which professions warranted travel in Medieval times?

How do so many people here on Academia.SE, and in general, afford lavish higher education programs?

Trouble downloading packages list due to a “Hash sum mismatch” error