Day 6 : Variables, Secrets, Artifacts & Complete CI/CD Workflow

Search for a command to run...

No comments yet. Be the first to comment.
Master GitLab from scratch with this complete step-by-step DevOps series. Learn GitLab fundamentals, repositories, branching, merge requests, CI/CD pipelines, GitLab Runner, Docker, Kubernetes integration, security, deployments, and real-world DevOps workflows. Whether you're a beginner or preparing for DevOps interviews, this series will help you gain practical GitLab skills through hands-on examples and projects.
Learn GitLab fundamentals, architecture, GitHub vs GitLab, Bitbucket comparison, CI/CD pipelines, and why enterprises choose GitLab for modern DevOps..
Learn GitLab Runners, Hosted vs Self-Hosted Runners, Runner Registration, Tags, Pipeline Editor & Parallel Jobs π Introduction In the previous article, we created our first GitLab CI/CD pipeline and

Learn Continuous Integration, Continuous Delivery, Pipelines, Stages, Jobs & .gitlab-ci.yml π Introduction In the previous articles, we explored GitLab fundamentals, repository management, and collab

Learn Docker Scout, Multi-Stage Builds, Docker Hardened Images (DHI), SBOM, Docker Model Runner, Ask Gordon AI, and production-ready container security through practical, real-world examples. Introduc

Import Repositories, Mirroring & Repository Management Best Practices π Introduction In the previous articles, we learned the fundamentals of GitLab, created projects, and configured secure authentic

Master GitLab CI/CD Variables, Secrets Management, Artifacts & Best Practices
In the previous article, we learned how GitLab Runners execute CI/CD pipelines and how to configure Self-Hosted Runners.
Now it's time to learn one of the most important topics in GitLab CI/CDβVariables, Secrets, and Artifacts.
Instead of hardcoding sensitive information like API keys, passwords, or cloud credentials, GitLab provides a secure way to manage them using CI/CD Variables. You'll also learn how to store build outputs using Artifacts and follow best practices for building secure and maintainable pipelines.
By the end of this article, you'll be able to create more secure, production-ready GitLab CI/CD pipelines.
After completing this article, you'll understand:
β What are CI/CD Variables?
β Protected Variables
β Masked Variables
β Expanded Variables
β Secrets Management
β Artifacts
β Artifact Expiry
β Common CI/CD Errors
β CI/CD Best Practices
Before continuing, make sure you have:
A GitLab account
A GitLab repository
A working GitLab CI/CD pipeline
Basic knowledge of GitLab CI/CD
CI/CD Variables are key-value pairs used to store configuration values and sensitive information securely. Instead of hardcoding values inside the .gitlab-ci.yml file, you can store them as variables and use them during pipeline execution.
For example, instead of writing an API key directly in your pipeline, you can reference it as a variable.
variables:
APP_NAME: "GitLab Practice"
build:
script:
- echo $APP_NAME
Protected Variables are only available to pipelines running on protected branches or protected tags.
They are commonly used for production credentials such as:
Production API Keys
Database Passwords
Cloud Credentials
This prevents sensitive data from being exposed in feature branches.
Masked Variables hide sensitive values from pipeline logs.
For example, if a variable contains an API key or password, GitLab replaces the actual value with **** in the job logs.
This helps prevent accidental exposure of secrets.
Expanded Variables allow one variable to reference another.
Example:
variables:
APP_NAME: "gitlab-app"
IMAGE_NAME: "$APP_NAME:v1"
GitLab automatically expands the referenced value during pipeline execution.
Sensitive information such as passwords, API keys, AWS credentials, and database URLs should never be stored directly in your repository.
Instead, save them in Settings β CI/CD β Variables and reference them inside your pipeline.
deploy:
script:
- echo "$AWS_ACCESS_KEY_ID"
Artifacts are files generated during a pipeline that can be stored and downloaded after a job completes.
Common examples include:
Build output
Reports
Log files
Test results
Example:
build:
script:
- mkdir dist
- echo "Build Complete" > dist/output.txt
artifacts:
paths:
- dist/
Artifacts can be configured to expire automatically after a specific period.
artifacts:
paths:
- dist/
expire_in: 7 days
Some common issues you may encounter include:
Invalid .gitlab-ci.yml syntax
Runner Offline
Missing CI/CD Variables
Permission Denied
Pipeline Failed
Review the pipeline logs to identify and resolve these errors quickly.
Store secrets using CI/CD Variables.
Never hardcode passwords or tokens.
Use Protected Variables for production.
Mask sensitive credentials.
Configure artifact expiry.
Validate your .gitlab-ci.yml before deployment.
Congratulations! π You have completed Day 6 of the GitLab learning series.
In this article, you learned how to securely manage CI/CD Variables, protect sensitive information using Protected and Masked Variables, use Artifacts to store build outputs, configure Artifact Expiry, and follow CI/CD best practices for production-ready pipelines.
You have successfully completed the GitLab DevOps Learning Series.
You now have a solid understanding of GitLab fundamentals, repositories, CI/CD pipelines, GitLab Runners, Variables, Secrets, and Artifacts. These concepts provide a strong foundation for building secure and production-ready DevOps workflows using GitLab.