.gitlab-ci.yml Part Nine – Basics Of Default Inherit
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed .gitlab-ci.yml features like include, extends and pages.
https://cloudaffaire.com/gitlab-ci-yml-part-eight-basics-of-include-extends-pages/
In this blog post, we will discuss .gitlab-ci.yml features like default and inherit.
default:
Some parameters can be set globally as the default for all jobs using the default: keyword. Default parameters can then be overridden by job-specific configuration. The following job parameters can be defined inside a default: block:
- image
- services
- before_script
- after_script
- tags
- cache
- artifacts
- retry
- timeout
- interruptible
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
################################################### ## .gitlab-ci.yml Part Nine : default | inherit ## ################################################### ## Prerequisites: GitLab Access Token ## https://cloudaffaire.com/how-to-create-a-gitlab-project-using-api/ ## One CentOs system with internet access ## git, curl and jq package installed ## ------------------------------------ ## Create A GitLab Project To Play With ## ------------------------------------ ## Create a project in GitLab ## GitLab Console => Projects => Your Projects => New Project => PROJECT_ID=$(curl --silent --header "PRIVATE-TOKEN: -XPOST "https://gitlab.com/api/v4/projects?name=cloudaffairecicd&visibility=private&initialize_with_readme=true" | jq '.id') ## Get the ssh clone url for your project ## GitLab Console => Projects => Your Projects => GIT_SSH_CLONE_URL=$(curl --silent --header "PRIVATE-TOKEN: -XGET "https://gitlab.com/api/v4/projects/$PROJECT_ID" | jq -r '.ssh_url_to_repo') ## Clone your GitLab project repository git clone $GIT_SSH_CLONE_URL ## ------- ## default ## ------- ## Create the pipeline configuration file cd cloudaffairecicd && vi .gitlab-ci.yml --------------------- default: image: ubuntu:latest tags: [docker] retry: 2 timeout: 1m stages: - stageone - stagetwo job1: stage: stageone script: - echo "job1 inherits all default configuration" job2: stage: stagetwo image: ruby:latest script: - echo "job2 inherits all default configuration except image" --------------------- :wq ## Push the .gitlab-ci.yml file into GitLab git add . git commit -m "jobs with default" git push |
inherit:
You can disable inheritance of globally defined defaults and variables with the inherit: parameter. To enable or disable the inheritance of all variables: or default: parameters, use the following format:
- default: true or default: false
- variables: true or variables: false
To inherit only a subset of default: parameters or variables:, specify what you wish to inherit in an array, and any not listed will not be inherited.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
## ------- ## inherit ## ------- ## Edit the pipeline configuration file cat /dev/null > .gitlab-ci.yml && vi .gitlab-ci.yml --------------------- default: image: ubuntu:latest tags: [docker] retry: 2 timeout: 1m stages: - stageone - stagetwo job1: stage: stageone inherit: default: false script: - echo "job1 will not inherit default configuration" job2: stage: stagetwo image: ruby:latest script: - echo "job2 inherits all default configuration except image" --------------------- :wq ## Push the .gitlab-ci.yml file into GitLab git add . git commit -m "jobs with inherit" git push ## Delete your project curl --silent --header "PRIVATE-TOKEN: -XDELETE "https://gitlab.com/api/v4/projects/$PROJECT_ID" | jq '.' cd .. && rm -rf cloudaffairecicd |
Hope you enjoyed this article. In the next blog post, we will continue our discussion .gitlab-ci.yml.
To get more details on GitLab you can follow the below link.
https://docs.gitlab.com/ee/README.html
To Get more details on Git you can follow the below links.
https://cloudaffaire.com/category/devops/git/