YAML
YAML is a human-readable data serialization format. It is used for configuration files, deployment manifests, and data exchange between languages with different data structures.
Basic Syntax
Key-Value Pairs:
Simple assignments.
name: John Doe
age: 30Lists:
Sequential arrays of data.
hobbies:
- reading
- hiking
- codingMaps:
Nested key-value assignments.
person:
name: Jane
age: 25Comments:
Anything after # is a comment.
Advanced Constructs
Multiline Strings:
Using the | character.
Anchors & Aliases:
Allow for duplicating properties.
Merging Data:
Combine data from two sources.
GitLab's .gitlab-ci.yml
.gitlab-ci.ymlUsually, YAML is used to write CI/CD pipelines, we will see a high level overview of how its used in GitLab pipelines.
The .gitlab-ci.yml file, employed by GitLab for CI/CD, is an excellent real-world example of YAML's utility.
Key Components
image: Specifies the Docker image for CI/CD tasks.stages: Different stages of CI/CD, likebuild,test, anddeploy.before_script: Commands run before all jobs.job: Defines commands for a specific stage.
Example Configuration:
Advanced Concepts in .gitlab-ci.yml
.gitlab-ci.ymlcache: Caches directories between runs, like dependencies.variables: Pre-defined environment variables.tags: Labels assigned to runners to control job execution locations.
Last updated
