Crea ng a Mul -Stage CI/CD Pipeline using GitLab
By: G B NAGESH KUMAR
VIJAYA VITTALA INSTITUTE OF TECHNOLOGY
Date: 29-11-2024
BATCH ID -2737877
Overview
This document provides a step-by-step guide to crea ng a mul -stage CI/CD pipeline in GitLab. It includes se ng up
your GitLab project, configuring the .gitlab-ci.yml file, and verifying pipeline execu on.
1. Se ng Up Your GitLab Project 1. Create a New GitLab Project:
o Log in to your GitLab account.
o Click on Create New Project.
2. Navigate to the Repository:
o Once the project is created, navigate to the Repository sec on in the le -hand menu.
2. Crea ng the .gitlab-ci.yml File
1. Create and Configure the File:
o In the repository, click Add File > New File.
2. Add the Pipeline Configura on:
stages: -
prepare
- build
- test
- deploy
- cleanup
prepare:
stage: prepare
script:
- echo "Star ng the pipeline"
- echo "Prepare stage completed!"
build:
stage: build
script:
- echo "Building the applica on..."
- echo "Hello, World! from the build stage"
test:
stage: test
script:
- echo "Running tests..."
- echo "Hello, World! from the test stage"
deploy:
stage: deploy
script:
- echo "Deploying the applica on..."
- echo "Hello, World! from the deploy stage"
cleanup:
stage: cleanup
script:
- echo "Cleaning up resources..."
- echo "Pipeline execu on completed successfully!"
3. Commit the Changes:
o Click the Commit Changes bu on.
o This saves the .gitlab-ci.yml file to the repository.
3. Checking the CI/CD Pipeline 1. Verify Pipeline Execu on:
o Navigate to CI/CD > Pipelines from the le -hand menu.
2. Trigger the Pipeline Manually (if needed):
o Click on Run Pipeline in the Pipelines sec on.
o Choose the branch where the .gitlab-ci.yml file was commi ed (usually main) and click Run Pipeline.
4. Monitoring the Pipeline
1. View Pipeline Stages:
o Once the pipeline starts, you’ll see the stages (Prepare, Build, Test, Deploy, Cleanup) listed in the Pipelines
sec on.
2. Inspect Logs:
o Click on individual stages to view their execu on logs.
5. Debugging and Itera ng
1. If the Pipeline Fails:
o Click on the failed stage in the Pipelines sec on to view error logs.
o Edit the .gitlab-ci.yml file to fix any issues. o Commit the changes to automa cally retry the pipeline.
6. Conclusion
By following these steps, you can successfully set up a mul -stage CI/CD pipeline in GitLab. This pipeline helps automate
key stages such as prepara on, building, tes ng, deployment, and cleanup. Use the pipeline logs to debug and refine your
workflow as needed.