basic-shell.gitlab-ci

Learn how to define Gitlab CI/CD pipelines using YAML. This example demonstrates build, test, and deploy stages with before and after scripts. Easily manage your CI/CD workflows with this clear and concise guide.

Gitlab CI YAML Example

This example demonstrates a basic Gitlab CI/CD pipeline defined in YAML. It includes build, test, and deploy stages, along with before and after scripts.

Pipeline Stages

The pipeline is divided into three stages: build, test, and deploy. Each stage contains one or more jobs.

Build Stage

The build stage contains a single job, build_job_a, which simply echoes a message.

Test Stage

The test stage contains two jobs, test_job_a and test_job_b, both echoing messages. In a real-world scenario, these jobs would run tests.

Deploy Stage

The deploy stage contains a single job, deploy_job, which echoes a message and runs some system commands. In a real-world scenario, this job would deploy the application.

Before and After Scripts

Before and after scripts are executed before and after all jobs in the pipeline, respectively. These are useful for tasks such as setting up the environment or cleaning up after the pipeline has run.

stages:
  - build
  - test
  - deploy

before_script:
  - echo "::before script section::"

after_script:
  - echo "::after script section::"

build_job_a:
  stage: build
  script:
    - echo "building job a"

test_job_a:
  stage: test
  script:
    - echo "testing job a"

test_job_b:
  stage: test
  script:
    - echo "testing job b"

deploy_job:
  stage: deploy
  script:
    - echo "deploy job"
    - uname -a
    - uptime
    - docker ps

This is a simple example, and can be expanded to include more complex tasks and configurations. Refer to the Gitlab CI/CD YAML documentation for more information.