我在 git 企业环境中,有一个 git repo,我将整个代码拉到其中,然后使用gulp.js然后将分发复制到另一个 repo,在那里我将其推送到远程。
我已经在 bash 脚本中自动执行了所有这些操作,每次执行时sh gittogulp.sh
都能完美无缺。但是当我使用 cronjob 执行此操作时,它无法从 git 中提取新内容,并且使 gulp.js 从已有内容中构建。
我想知道,如何才能从 git repo 中提取数据而不手动触发脚本。Webhooks 对我来说不是一个选择。
gittogulp.sh
是:
#!/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