Git Pull and then Push via Cron in Ubuntu
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
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
bash scripts cron git
add a comment |Â
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
bash scripts cron git
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
add a comment |Â
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
bash scripts cron git
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
bash scripts cron git
edited Feb 17 at 9:46
asked Feb 17 at 8:56
![](https://i.stack.imgur.com/fPKCA.jpg?s=32&g=1)
![](https://i.stack.imgur.com/fPKCA.jpg?s=32&g=1)
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
add a comment |Â
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
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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