[英]How to make a simple GitLab Ci/CD gitlab-ci.yml file to build an Angular project?
This is for an Angular project I have.这是针对我拥有的 Angular 项目的。
The project itself builds and runs just fine.该项目本身构建并运行得很好。 I have just been struggling with trying to figure out how to make my 1st CI/CD pipeline process gitlab-ci.yml file.
我一直在努力弄清楚如何制作我的第一个 CI/CD 管道流程gitlab-ci.yml文件。 This has been going on for months.
这种情况已经持续了几个月。
How the heck is this to be setup because I cannot find a basic example that just works.这是如何设置的,因为我找不到一个可以正常工作的基本示例。
image: node:14.17.0
stages: # List of stages for jobs, and their order of execution
- setup
- build
- cleanup
.pre:
stage: setup,
script:
- mkdir -p dist
- npm install -g @angular/cli@12.2.16
- npm install # or `npm install` or whatever you use to install deps
- npm start
- npm --version
cache:
paths:
- node_modules
policy: pull
build-job:
stage: build
script: # ... your other build steps here
- npm run build_def_mysetup
- ls /builds
cache:
paths:
- node_modules
policy: pull
artifacts:
paths:
- dist/
.post:
stage: cleanup
script:
- echo "cleanup called"
The goal right now for this is to现在的目标是
I say eventually because I cannot get #1 to work我说最终是因为我无法让#1 工作
Alright, i had a quick glance at your pipeline and tried it on an angular project.好的,我快速浏览了您的管道并在 angular 项目上进行了尝试。 First, by following the gitlab-ci documentation, you should not mix stages, with
.pre
and .post
.首先,通过遵循gitlab-ci文档,您不应将阶段与
.pre
和.post
混合使用。 please take a look at Gitlab CI stages , in this matter.请看一下Gitlab CI 阶段,在这件事上。
Next, for the matter of artifacts, you do not need to specifically set path to artifacts, as they are kept between subsequent stages.接下来,关于工件,您不需要专门设置工件的路径,因为它们保留在后续阶段之间。
Now for the pipeline现在为管道
- -
Install dependencies - node_modules安装依赖项 - node_modules
stage: install_dependencies image: node:14 script: - npm install
Install angular安装 angular
stage: install_angular image: node:14 script: - npm install -D typescript @angular/cli @angular/compiler
Build angular app构建 angular 应用程序
stage: build image: node:14 script: - npm run build
Notify if the build fails构建失败时通知
Run unit tests + release运行单元测试+发布
The full pipeline would look something like this (its a trivial example, it can be merged into one stage)完整的管道看起来像这样(这是一个简单的例子,它可以合并到一个阶段)
image: node:14.17.0
stages: # List of stages for jobs, and their order of execution
- install_dependencies
- install_angular
- build
install_dep:
stage: install_dependencies
image: node:14
script:
- npm install
install_ang:
stage: install_angular
image: node:14
script:
- npm install -D typescript @angular/cli @angular/compiler
build_ang:
stage: build
image: node:14
script:
- npm run build
This is what my current file has.这是我当前文件的内容。 I needed the artifact in here otherwise ng would not work.
我需要这里的工件,否则 ng 将无法工作。
image: node:14.17.0 # This is the container for our Docker we will build in
cache:
paths:
- dist/
- node_modules/
stages: # List of stages for jobs, and their order of execution
- install_dependencies
- install_angular
- build
install_dep:
stage: install_dependencies
image: node:14
script: # Execute script commands just as you would on terminal command line
- echo $CI_PROJECT_DIR
- npm install
- echo npm --version
artifacts: # This is required for other stage to have access to what gets created
paths:
- node_modules/
install_ang:
stage: install_angular
image: node:14
script:
- npm install -D typescript @angular/cli@12.2.16 @angular/compiler@12.2.16
# Possible that the -D is optional could use -g or none
build:
stage: build
script:
- npm run build_def_mybuild # this is defined in angular.json
- ls dist/
This is as far as I"ve made it. I may need the following for doing tests.这是我所做的。我可能需要以下内容进行测试。
artifacts: # This is required for other stage to have access to what gets created
paths:
- dist/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.