我正在尝试使用gitlab管道构建和部署我的角度项目。有两个工作。一种用于构建有角度的应用程序,另一种用于部署。我的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
在部署作业中使用的aws cli构建位于我项目根目录中的dockerfile。我的问题是 每次运行部署作业时,都会出现此错误:
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.
似乎缺少上一个构建作业中的工件。我的gitlab-ci.yaml
文件有什么问题?
答案 0 :(得分:2)
将工件提取到其他管道步骤时,会将其提取到通过git下拉代码的位置。对我来说,我已经看到了放置在我的代码所在的父目录中的工件。因此,例如,如果我具有以下目录结构:
--- gitlab_ci_root
--- my_code
提取的工件将放置在gitlab_ci_root
下,而不是my_code
下。
您可以通过在您的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
一旦找到要解压缩dist/
目录的位置,则可以在脚本中将dist转换为所需的位置。