
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Gitlab pipeline creation along with its components and stages
Gitlab offers various features and one of them is pipeline. Gitlab pipeline is used to perform continuous integration, continuous deployment ,code quality checks, security checks, artifact storage etc. The .gitlab-ci.yml file plays a vital role in the gitlab pipeline. All the pipeline configuration is written in the .gitlab-ci.yml file.CI/CD pipeline can run automatically when events are triggered like pushing to a branch , merging to a branch etc.
Pipeline Components
Jobs and Stages together form the pipeline. YAML keywords are used to define the stages and jobs.
Pipeline Steps
1. Create a project in the gitlab
2. Ensure you have runners available for your project (runners are available by default)
3. Select a branch in which you want to create a pipeline
4. Create gitlab-ci.yml file in the root directory of the project where all the configuration related to CI/CD is written
5. Write your CI/CD code in the gitlab-ci.yml file.
Example
build:
stage: build
script:
- echo "Hello, Gitlab Pipeline!"
test:
stage: test
script:
- echo "This job tests Pipeline demo project."
deploy:
stage: deploy
script:
- echo "This job deploys jar from the main branch into dev env"
environment: dev
6. Select Commit changes
7. If your configuration is valid, you will see banner saying Your Gitlab CI configuration is valid
Otherwise you will see Invalid configuration banner like below
8. Go to Build ? Pipelines on the left hand side menu and you will see all the failed and successful pipelines.
We have configured 3 stages for this pipeline Build, Test and Deploy.
9. You can see each job by clicking on it, for example "test" stage
Run a job manually:
In real time scenarios, we may come across some scenarios where manual interaction is needed to run the job. The best example for manual job is "deployment into production" . Gitlab offers manual jobs run by adding "When : manual" in the .gitlab-ci.yml file.
Example
build:
stage: build
script:
- echo "Hello, Gitlab Pipelne!"
test:
stage: test
script:
- echo "This job tests Pipeline demo project."
deploy:
stage: deploy
script:
- echo "This job deploys artifact from the main branch into prod environment."
environment: production
when : manual
Manual jobs are displayed as skipped when the pipeline runs like below. As we defined "deploy" job as a manual job, so it is shown as skipped.

You can run manual run by clicking on run button.

You can add a confirmation alert before running a sensitive job.
Example
build:
stage: build
script:
- echo "Hello, Gitlab Pipeline!"
test:
stage: test
script:
- echo "This job tests Pipeline demo project."
deploy:
stage: deploy
script:
- echo "This job deploys artifacts from the main branch into the prod environment."
environment: production
when : manual
manual_confirmation : "Are you sure you want to deploy into Production?"
To use "manual_confirmation" ,"when : manual" is a must. WIthout "when : manual" , "manual_confirmation" has no effect on the job.
Run a pipeline at scheduled intervals
Gitlab offers scheduled runs for the pipeline. You can create a pipeline and run it everyday, every week, every month etc. You can customize the schedule by giving regular expressions also.To create a scheduled pipeline go to Build ? Pipeline Schedules