简体   繁体   English

Gitlab CI Angular Artifacts 无法访问

[英]Gitlab CI Angular Artifacts not accessible

I'm trying to build and deploy my angular project with gitlab pipelines.我正在尝试使用 gitlab 管道构建和部署我的 angular 项目。 There are two jobs.有两个工作。 One for building the angular app and one for the deployment.一种用于构建 angular 应用程序,一种用于部署。 My gitlab-ci.yml looks like this.我的gitlab-ci.yml看起来像这样。

image: node:latest

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
  - node_modules/

before_script:
  - npm install > /dev/null

stages:
  - build
  - deploy

build:
    stage: build
    artifacts: 
        paths:
            - dist/
        expire_in: 1 week
    script:
        - npm run build --prod

deploy:
  stage: deploy
  dependencies:
    - build
  environment: production
  image: mjsarfatti/gitlab-ci-pipeline-php-aws:latest
  before_script:
    - mkdir ~/.aws/
    - touch ~/.aws/credentials
    - printf "[eb-cli]\naws_access_key_id = %s\naws_secret_access_key = %s\n" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" >> ~/.aws/credentials
  script:
    - git checkout master
    - eb deploy my_project
  only:
    - master

The aws cli used in the deploy job builds the dockerfile located in my project root.部署作业中使用的 aws cli 构建了位于我的项目根目录中的 dockerfile。 My problem is that every time when I run the deploy job I get this error:我的问题是每次运行部署作业时都会收到此错误:

Step 3/7 : COPY dist/src /usr/share/nginx/html
44 COPY failed: stat /var/lib/docker/tmp/docker-builder648218383/dist/src: no such file or directory.

It seems like that the artifact from the previous build job is missing.上一个构建作业的工件似乎丢失了。 What is wrong with my gitlab-ci.yaml file?我的gitlab-ci.yaml文件有什么问题?

When artifacts are extracted into other pipeline steps, it's extracted in a different location that your code that's pulled down via git.当工件被提取到其他管道步骤中时,它会被提取到您通过 git 下拉的代码的不同位置。 For me, I've seen the artifact(s) put in the parent directory from where my code is.对我来说,我已经看到工件放在我的代码所在的父目录中。 So for example if I have this directory structure:例如,如果我有这个目录结构:

--- gitlab_ci_root
   --- my_code

The extracted artifacts will be put under gitlab_ci_root , not my_code .提取的工件将放在gitlab_ci_root下,而不是my_code

You can test this by putting a couple of ls 's into your deploy step.您可以通过将几个ls放入deploy步骤来测试这一点。

deploy:
  stage: deploy
  dependencies:
    - build
  environment: production
  image: mjsarfatti/gitlab-ci-pipeline-php-aws:latest
  before_script:
    - ls # directory list of current directory, likely your code
    - ls ../ # directory list of the parent directory.
    - mkdir ~/.aws/
    - touch ~/.aws/credentials
    - printf "[eb-cli]\naws_access_key_id = %s\naws_secret_access_key = %s\n" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" >> ~/.aws/credentials
  script:
    - git checkout master
    - eb deploy my_project
  only:
    - master

Once you find where the dist/ directory is being extracted, then in your script you can mv the dist to wherever you need it to be.一旦找到dist/目录的解压位置,您就可以在脚本中将 dist 移动到您需要的任何位置。

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

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