Feedback

Chat Icon

Cloud Native CI/CD with GitLab

From Commit to Production Ready

GitLab CI/CD Core Concepts
37%

Defaut Stages: ".pre" and ".post"

In our CI YAML file, we have defined two stages: build and test. However, GitLab CI/CD has two default stages: .pre and .post. These stages are always executed at the beginning and end of the CI/CD pipeline, respectively.

  • The .pre stage can serve as a preparation/check stage before the pipeline runs.
  • The .post stage can be used for anything that you want to run after the pipeline completes like sending notifications.

Here is a simple example of how to use these stages:

  • The pre-build job checks the Python version in the python:3.12 image before running the pipeline
  • The post-test job posts a message to Slack when the pipeline completes. The code to use is as follows:
export SLACK_WEBHOOK= && cat <$HOME/todo/app/.gitlab-ci.yml
image: python:3.12

stages:
  - build  
  - test  

pre-build:
  stage: .pre
  script:
    # Check the Python version before running the pipeline
    - >
      python3 --version |
      grep "Python 3.12" ||
      exit 1

build:
  stage: build  
  script:
    - pip install -r requirements.txt

test:
  stage: test  
  script:
    - pip install -r requirements.txt
    - pip install flake8==7.1.1
    - flake8 --statistics
    - python3 test_app.py  

post-test:

Cloud Native CI/CD with GitLab

From Commit to Production Ready

Enroll now to unlock all content and receive all future updates for free.