Gitlab CI如何部署PHP?

我使用gitlab,gitab-ci,我对Continuous Integration来说很新.我尝试在代码推送上测试和部署bash脚本.

这就是我的.gitlab-ci.yml在部署中的样子我试图改变用户但不起作用

before_script:
  - composer install --prefer-dist > /dev/null

stages:
  - build
  - test
  - deploy


unitTesting:
  stage: test
  script:
    - echo "Running PHPUnit Tests"
    - php vendor/bin/phpunit --colors --debug  --coverage-text

job_deploy_master:
  stage: deploy
  only:
    - master
  script:
    - /bin/su - myuser -c "deploy.sh" //here I try to change linux user to be able to checkout code but fails with  **su: must be run from a terminal**
  tags:
    - php

在这里我有bash,如果测试通过,它应该在生产现场拉代码

#!/bin/bash

echo "Starting Deploy"
printf '%s\n' "${SUDO_USER:-$USER}" //I'm interested to see which user try to run this script outputs gitlab-runner
cd /home/builds/gpx-convertor
git pull
composer install --prefer-dist > /dev/null

我试图谷歌找到一些与PHP相关的例子,但没有成功.有人可以说明应该如何运作

最佳答案 尝试用sudo -Hu替换su -c

点赞