How do I use the inherit section in a pipeline as code?

Modified on Wed, 21 Jun 2023 at 02:48 PM

I'm sorry, but the inherit section is not a valid configuration option in GitLab pipelines as code. There is no built-in inherit section in GitLab's pipeline configuration syntax.


However, you can achieve similar results by using other features and techniques available in GitLab's pipeline configuration. For example, you can leverage the YAML anchors and aliases to reuse common configuration elements across multiple jobs or stages within your pipeline.


Here's an example of how you can use YAML anchors and aliases to achieve a form of inheritance:


.default_configuration: &default_config
  script:
    - echo "Default script"
stages:
  - build
  - test

job_build:
  stage: build
  <<: *default_config
  script:
    - echo "Custom build script"

job_test:
  stage: test
  <<: *default_config
  script:
    - echo "Custom test script"


In the above example, the .default_configuration anchor defines the default configuration, which is then reused in the job_build and job_test jobs using the <<: *default_config alias.


By utilizing YAML anchors and aliases, you can achieve a form of inheritance and reuse common configuration elements across multiple jobs or stages within your GitLab pipeline.


Remember, if you encounter any issues or need further assistance with your pipelines, Cloud-Runner offers comprehensive support and expertise in optimizing CI/CD workflows. Visit cloud-runner.com to explore how Cloud-Runner can enhance your GitLab pipelines and streamline your development processes.





Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article