Php 使用yml文件gitlab自动克隆git
我正在尝试使用gitlab yml文件在服务器上设置自动git克隆/拉取 如何使用yml脚本检查git存储库是否存在,如果存在,则使用git拉取,否则使用git克隆。 我想要以下输出:Php 使用yml文件gitlab自动克隆git,php,git,yaml,gitlab,Php,Git,Yaml,Gitlab,我正在尝试使用gitlab yml文件在服务器上设置自动git克隆/拉取 如何使用yml脚本检查git存储库是否存在,如果存在,则使用git拉取,否则使用git克隆。 我想要以下输出: If GIT REPO NOT EXIST then git clone else no action 下面是我的yml文件,有人能帮我吗 cache: paths: - vendor/ before_script: - php -v - pwd - mkdir -p /v
If GIT REPO NOT EXIST then
git clone
else
no action
下面是我的yml文件,有人能帮我吗
cache:
paths:
- vendor/
before_script:
- php -v
- pwd
- mkdir -p /var/www/html
- if [ ! -d /var/www/html/.git ] then
- git clone http://username:password@XX.XX.XX.XXX/root/myproject.git /var/www/html
- fi
stages:
- deploy
deploy_staging:
stage: deploy
script:
- echo "Deploy to staging server"
environment:
name: staging
url: http://XX.XX.XX.XXX/
script:
- cd $webroot
- git pull
我假设您遇到了“意外的文件结尾”错误。首先,您错过了if的分号,它应该是if[!-d…];然后
如果我没记错的话,每个命令都是在自己的shell中执行的。
因此GitLab执行:
sh -c 'php -v'
sh -c 'pwd'
sh -c 'mkdir -p /var/www/html'
sh -c 'if [ ! -d /var/www/html/.git ] then'
sh -c 'git clone http://username:password@XX.XX.XX.XXX/root/myproject.git /var/www/html'
sh -c 'fi'
另一个问题是if、git克隆和fi未连接。因此,您可以使用多行字符串或使用一些速记:
before_script:
- php -v
- pwd
- mkdir -p /var/www/html
- [ -d /var/www/html/.git ] || git clone http://username:password@XX.XX.XX.XXX/root/myproject.git /var/www/html
这表示:如果目录检查失败(
[-d
在找不到目录时失败),执行git clone
。|
运算符是shell在命令失败时执行的,而&&
运算符是命令成功时执行的。尝试scandir
函数检查文件夹是否存在?谢谢@prakash,但我想在gitlab YML文件脚本中执行check,所以如果您知道ab关于YML文件脚本,请告诉我。谢谢你的回答,但我想使用gitlab CI YML文件执行命令,你提到了sh命令,所以这不适用于gitlab YML命令。@Girish Patidar只要gitlab调用sh就行了,这就是我的意思。