CI/CD Pipeline to Deploy Angular on AWS with GitLab Runner
Date
May 16, 24
Reading Time
2 minutes
Category
Technology
- What are CI and CD?
- CI/CD using GitLab
Table of content

What are CI and CD?
Continuous Integration (CI) is a development practice of merging all code developed by developers into a shared repository. Each integration is then verified by an automated build, allowing teams to detect problems quickly and resolve them in a very efficient way.
Continuous Delivery helps to deploy our app/software at any time, generally done when we push our code to the staging environment.
Continuous Deployment deploys code to the production environment, often done when we merge our code to the main branch.
Gitlab provides a nice way to support CI Integration and to utilize that we need to create a .gitlab-ci.yml file in our project directory.
Now, If you commit to your master branch with .gitlab-ci.yml and files in the root directory of your project then the CI/CD pipeline will initiate the set of instructions that we described below.
CI/CD using GitLab
# Node Image for docker on which code will execute
image: node:latest
stages:
- build
deploy_master:
stage: deploy
before_script:
- npm install
- npm run build -- --prod
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- chmod 400 $PRIVATE_KEY_STAGING
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- apt-get update -y
- apt-get -y install rsync
script:
- ssh -i PRIVATE_KEY SERVER_NAME@SERVER_IP
- rsync -zvhr -auv -e "ssh -i PRIVATE_KEY dist/ ubuntu@SERVER_IP:/
only: ['master']