Feedback

Chat Icon

Cloud Native CI/CD with GitLab

From Commit to Production Ready

Consice, Reusable and Refactored Definitions
24%

Combining "extends" with "include" for More Reusability

If the sections you want to extend are long or complex or if you want to share them across multiple projects, you can define them in separate files and include them in the main pipeline definition.

In this case, we can combine the extends keyword with the include keyword. This is an example:

Step 1: Create the file base_test.yml:

cat <$HOME/todo/app/.includes/base_test.yml
# base_test.yml
.base_test:
  stage: test
  image: alpine:latest
  before_script:
    - echo "Setting up the environment..."
  after_script:
    - echo "Cleaning up..."
EOF

Step 2: Create the main pipeline definition and include the base_test.yml file:

cat <$HOME/todo/app/.gitlab-ci.yml
# .gitlab-ci.yml
stages:
  - test

include:
  - local: '.includes/base_test.yml'

Cloud Native CI/CD with GitLab

From Commit to Production Ready

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