简体   繁体   English

由于“没有这样的文件或目录”错误,GitLab-runner 未能成功完成

[英]GitLab-runner fails to finish successfully due to “No such file or directory” error

I am using laravel-deployer package for deployment my project on my server.我正在使用 laravel-deployer package 在我的服务器上部署我的项目。 I have the following gitlab-ci file:我有以下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

It basically deploy laravel website, removes the previous version, copies the new one and changes its permissions so its readable by Nginx.它主要部署 laravel 网站,删除以前的版本,复制新版本并更改其权限,以便 Nginx 可读。 All the steps are executed correctly but it always fails after it finishes with the following error:所有步骤均已正确执行,但在完成并出现以下错误后总是失败:

✔
➤ 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

Even though the pipeline works, its bugging me that I can't get a Passed report badge.即使管道正常工作,我也无法获得通过报告徽章,这让我很烦恼。

Use利用

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

to avoid that error.以避免该错误。 And remove "cd" command.并删除“cd”命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM