将 dist 文件夹内容从 gitlab 移动到 aws 服务器实例时,我没有得到这样的文件或目录

I get no such file or directory when moving dist folder contents from gitlab to aws server instance

我是 Gitlab 的新手 CI/CD,一整天都在尝试解决这个问题,但没有任何效果。我正在尝试将构建阶段后由 gitlab runner 生成的 dist 文件夹移动到 aws ec2-instance 文件夹位置。我目前正在使用 Gitlab 实现 CI/CD 管道,这就是我的 .gitlab-ci.yml 的样子:

# Node Image for docker on which code will execute
image: node:latest

# This is the stages / task to perfom in jobs
stages:
  - build
  - deploy

# caching for reuse 
cache:
  key: "$CI_COMMIT_REF_SLUG"
  paths:
  - node_modules/

# This command is run before the execution of stages
before_script:
  - npm install

# Job One for making build
build_testing_branch:
  stage: build
  script:
    - node --max_old_space_size=4096 --openssl-legacy-provider ./node_modules/@angular/cli/bin/ng build --configuration=dev-build --build-optimizer
  only: ['testing']

# Job Two for deploy build to server
deploy_testing_branch:
  stage: deploy

  before_script:
        - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
        - eval $(ssh-agent -s)
        # - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
        - mkdir -p ~/.ssh
        - chmod 700 ~/.ssh
        - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
        # - apt-get update -y
        # - apt-get -y install rsync

  artifacts:
    paths:
      - dist/

  script:
    - ssh-add <(echo "$SSH_PRIVATE_KEY")
    - ssh -p22 ubuntu@$SERVER_IP "rm -r /usr/share/nginx/user-host/ui-user-host/dist/; mkdir /usr/share/nginx/user-host/ui-user-host/dist/"
    - scp -P22 -r  $CI_PROJECT_DIR/dist/ ubuntu@$SERVER_IP:/usr/share/nginx/user-host/ui-user-host/dist/

  only: ['testing']

构建过程在确认成功后运行良好,但部署阶段失败,因为我得到:

$scp -P22 -r  $CI_PROJECT_DIR/dist/ ubuntu@$SERVER_IP:/usr/share/nginx/user-host/ui-user-host/dist/
/builds/user-live/ui-user-host/dist: No such file or directory
Cleaning up project directory and file based variables

所以,我不明白为什么它无法在上述位置找到 dist 文件夹。如果我正确理解这应该在 gitlab runner 的文件系统上可用。是不是scp命令不对?

编辑:

我也试过

- scp -P22 -r  dist/ ubuntu@$SERVER_IP:/usr/share/nginx/user-host/ui-user-host/dist/

- scp -P22 -r  dist/* ubuntu@$SERVER_IP:/usr/share/nginx/user-host/ui-user-host/dist/

但运气不好!

您正在 build_testing_branch 工作中构建您的 dist 文件夹并尝试在 deploy_testing_branch 中访问它为此工作您必须在 [=11] 中将 dist 文件夹作为工件=] 作业(因为 dist 是在那里创建的)而不是 deploy_testing_branch.