【问题标题】:GitLab-runner fails to finish successfully due to "No such file or directory" error由于“没有这样的文件或目录”错误,GitLab-runner 未能成功完成
【发布时间】:2021-02-18 08:16:02
【问题描述】:

我正在使用 laravel-deployer 包在我的服务器上部署我的项目。 我有以下gitlab-ci 文件:

stages:
  - build
  - test
  - deploy

image: lorisleiva/laravel-docker:7.4

.init_ssh: &init_ssh |
  eval $(ssh-agent -s)
  echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
  mkdir -p ~/.ssh
  chmod 700 ~/.ssh
  ssh-keyscan yourdomain.com >> ~/.ssh/known_hosts
  chmod 644 ~/.ssh/known_hosts

.change_file_permissions: &change_file_permissions |
  find . -type f -not -path "./vendor/*" -exec chmod 664 {} \;    
  find . -type d -not -path "./vendor/*" -exec chmod 775 {} \;

composer:
  stage: build

  script:
    - composer install --prefer-dist --no-ansi --no-interaction --no-progress
    - cp .env.production .env
    - php artisan key:generate

  artifacts:
    expire_in: 1 month
    paths:
      - vendor/
      - .env

  cache:
    key: ${CI_COMMIT_REF_SLUG}-composer
    paths:
      - vendor/

npm:
  stage: build
  cache:
    key: ${CI_COMMIT_REF_SLUG}-npm
    paths:
      - node_modules/
  script:
    - npm install
    - npm run production

  artifacts:
    expire_in: 1 month
    paths:
      - node_modules/
      - public/css/
      - public/js/

production:
  stage: deploy
  script:
    - *init_ssh
    - *change_file_permissions
    - cp .env.production .env
    - pwd
    - hostname
    - php artisan deploy yourdomain.com -s upload
    - cd /var/www/yourdomain.com/current
    - cp /var/www/yourdomain.com/current/.env.production /var/www/yourdomain.com/shared/.env
    - npm install
    - npm run production
  environment:
    name: production
    url: http://yourdomain.com
  when: manual
  only:
    - master

它基本上是部署 laravel 网站,删除以前的版本,复制新版本并更改其权限,以便 Nginx 可读。所有步骤都正确执行,但在完成后总是失败并出现以下错误:

✔
➤ Executing task artisan:migrate
✔
➤ Executing task deploy:symlink
✔
➤ Executing task deploy:unlock
✔
➤ Executing task cleanup
✔
➤ Executing task fpm:reload
✔
????  Successfully deployed in 16.63s
$ cd /var/www/yourdomain.com/current
/bin/bash: line 127: cd: /var/www/yourdomain.com/current: No such file or directory
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1

即使管道工作正常,但我无法获得通过报告徽章,这让我很烦恼。

【问题讨论】:

    标签: docker gitlab-ci gitlab-ci-runner artifact-deployer


    【解决方案1】:

    使用

    npm install /var/www/yourdomain.com/current --verbose
    npm run production --prefix /var/www/yourdomain.com/current
    

    以避免该错误。并删除“cd”命令。

    【讨论】:

    • 您安装的包 json 文件在哪里?定义该路径 "npm install PATH --verbose" "npm run production --prefix PATH"
    • 在我在 docker error987654321@ 上定义路径后得到了这个
    • 你为什么要运行“cd /var/www/yourdomain.com/current”命令?
    • 我运行这个是因为 - 为了复制我的 .env 文件,运行我的 php artisan tenancy:migratenpm
    • 复制命令不需要运行 cd。 cp就够了。并按照我上面提到的那样运行 npm。
    猜你喜欢
    • 2018-07-31
    • 1970-01-01
    • 2018-02-05
    • 2016-08-28
    • 2019-04-16
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多