Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git通过Ubuntu中的Cron拉入然后推入_Git_Automation_Cron - Fatal编程技术网

Git通过Ubuntu中的Cron拉入然后推入

Git通过Ubuntu中的Cron拉入然后推入,git,automation,cron,Git,Automation,Cron,一些上下文:我在一个git企业环境中,有一个git repo,在那里我拉取整个代码,一口气构建它,然后将发行版复制到另一个repo,在那里我将它推到远程 我已经在bash脚本中实现了所有这些的自动化,每当我执行shgittogulp.sh时,它都会完美地执行。但当我使用cronjob来实现这一点时,它无法从git中提取新内容,并从已有的内容中生成gulp构建 我想知道,如何在不手动触发脚本的情况下从git回购中提取。Webhooks不是我的选择:( gittogulp.sh是: #!/bin/b

一些上下文:我在一个git企业环境中,有一个git repo,在那里我拉取整个代码,一口气构建它,然后将发行版复制到另一个repo,在那里我将它推到远程

我已经在bash脚本中实现了所有这些的自动化,每当我执行
shgittogulp.sh
时,它都会完美地执行。但当我使用cronjob来实现这一点时,它无法从git中提取新内容,并从已有的内容中生成gulp构建

我想知道,如何在不手动触发脚本的情况下从git回购中提取。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

可能您不能使用
.sh
文件作为更改目录的终端,因此,我建议您使用以下方法(即使用
.sh
文件中的第1,2行):

另一个例子(如本地):

最后:
$fab pull


$fab push

请在HerdeOne上打开gittogulp.sh。@BenyaminJafari,你现在能帮忙吗?我有一条线路
npm安装
gulp dev
。我如何改变它的行为?我不知道。
git --git-dir=/home/<User>/<your_path>/.git checkout dev
...
from fabric.api import *

env.user = 'your_user'
env.hosts = ['127.0.0.1']
env.password = 'you_pswd'

@task
def pull():
    code_dir = '/srv/django/myproject'
    with cd(code_dir):
        run("git pull")
.
|-- __init__.py
|-- app.wsgi
|-- fabfile.py <-- our fabfile!
|-- manage.py
`-- my_app
    |-- __init__.py
    |-- models.py
    |-- templates
    |   `-- index.html
    |-- tests.py
    |-- urls.py
    `-- views.py
from fabric.api import *

@task
def push():
    local("git add -p && git commit")
    local("git push")