Published on: April 25, 2025
5 min read
Learn the basics of continuous integration/continuous delivery in this beginner's guide, including what CI/CD components are and how to create them.
Welcome to our "Getting started with GitLab" series, where we help newcomers get familiar with the GitLab DevSecOps platform.
Imagine a workflow where every code change is automatically built, tested, and deployed to your users. That's the power of Continuous Integration/Continuous Delivery (CI/CD)! CI/CD helps you catch bugs early, ensures code quality, and delivers software faster and more frequently.
GitLab CI/CD is a powerful, integrated system that comes built-in with GitLab. It offers a seamless experience for automating your entire software development lifecycle. With GitLab CI/CD, you can:
.gitlab-ci.yml
: This YAML file, located in your project's root directory, defines your CI/CD pipeline, including stages, jobs, and runners.Getting started with GitLab CI is simple. Here's a basic example of a .gitlab-ci.yml
file:
stages:
- build
- test
- deploy
build_job:
stage: build
script:
- echo "Building the application..."
test_job:
stage: test
script:
- echo "Running tests..."
deploy_job:
stage: deploy
script:
- echo "Deploying to production..."
environment:
name: production
This configuration defines three stages: "build," "test," and "deploy." Each stage contains a job that executes a simple script.
Let's explore some more realistic examples.
Building and deploying a Node.js application
The pipeline definition below outlines using npm to build and test a Node.js application and dpl to deploy the application to Heroku. The deploy stage of the pipeline makes use of GitLab CI/CD variables, which allow developers to store sensitive information (e.g. credentials) and securely use them in CI/CD processes. In this example, an API key to deploy to Heroku is stored under the variable key name $HEROKU_API_KEY
used by the dpl tool.
stages:
- build
- test
- deploy
build:
stage: build
image: node:latest
script:
- npm install
- npm run build
test:
stage: test
image: node:latest
script:
- npm run test
deploy:
stage: deploy
image: ruby:latest
script:
- gem install dpl
- dpl --provider=heroku --app=$HEROKU_APP_NAME --api-key=$HEROKU_API_KEY
Deploying to different environments (staging and production)
GitLab also offers the idea of Environments with CI/CD. This feature allows users to track deployments from CI/CD to infrastructure targets. In the example below, the pipeline adds stages with an environment property for a staging and production environment. While the deploy_staging stage will always run its script, the deploy_production stage requires manual approval to prevent accidental deployment to production.
stages:
- build
- test
- deploy_staging
- deploy_production
build:
# ...
test:
# ...
deploy_staging:
stage: deploy_staging
script:
- echo "Deploying to staging..."
environment:
name: staging
deploy_production:
stage: deploy_production
script:
- echo "Deploying to production..."
environment:
name: production
when: manual # Requires manual approval
GitLab Auto DevOps simplifies CI/CD by providing a pre-defined configuration that automatically builds, tests, and deploys your applications. It leverages best practices and industry standards to streamline your workflow.
To enable Auto DevOps:
Auto DevOps automatically detects your project's language and framework and configures the necessary build, test, and deployment stages. You don’t even need to create a .gitlab-ci.yml
file.
The CI/CD Catalog is a list of projects with published CI/CD components you can use to extend your CI/CD workflow. Anyone can create a component project and add it to the CI/CD Catalog or contribute to an existing project to improve the available components. You can find published components in the CI/CD Catalog on GitLab.com.
You can also create your own CI templates to standardize and reuse CI/CD configurations across multiple projects. This promotes consistency and reduces duplication.
To create a CI template:
.gitlab-ci.yml
file in a dedicated project or repository..gitlab-ci.yml
file, use the include
keyword to include the template.GitLab CI/CD is a powerful tool that can transform your development workflow. By understanding the concepts of CI/CD, configuring your pipelines, and leveraging features like Auto DevOps, the CI/CD Catalog, and CI templates, you can automate your entire software development lifecycle and deliver high-quality software faster and more efficiently.
Want to take your learning to the next level? Sign up for GitLab University courses. Or you can get going right away with a free 60-day trial of GitLab Ultimate.
Check out more articles in our "Getting Started with GitLab" series: