This is for an Angular project I have.
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. 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/[email protected]
- 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
- Install needed node_modules for the build
- Build the Angular application
- Eventually if build fails, notify via email the developer who last pushed the build
- Eventually if build pass - do nothing
- Eventually if build pass - Run unit tests
- Eventually if build pass and branch has release in name - tag the branch
I say eventually because I cannot get #1 to work
CodePudding user response:
Alright, i had a quick glance at your pipeline and tried it on an angular project.
First, by following the gitlab-ci documentation, you should not mix stages, with .pre
and .post
. please take a look at
Run unit tests release
- the same steps as previous steps
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
CodePudding user response:
This is what my current file has. I needed the artifact in here otherwise ng would not work.
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/[email protected] @angular/[email protected]
# 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/