User Tools

Site Tools


gitlabci

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
gitlabci [2022/09/22 14:19] skipidargitlabci [2022/09/22 16:35] (current) skipidar
Line 229: Line 229:
 === extends: syntax === === extends: syntax ===
  
 +
 +
 +=== <<: *my_anchor reuse properties with anchors ===
 +Using anchors you can reuse attriburtes across jobs,
 +especially from a disabled job:
 +
 +<sxh yaml>
 +
 +.deployment: &deployment
 +  image: path/to/image.jpg
 +  tags:
 +    - LAUNCHTAG
 +
 +
 +.deploy_to_prod:
 +  <<: *deployment
 +  variables: !reference [.env_variables, prod]
 +
 +.deploy_to_prodint:
 +  <<: *deployment
 +  variables: !reference [.env_variables, prodint]
 +  
 +</sxh>
 +
 +
 +=== !reference [.terraform, feature_destroy] ===
 +Reference some piece of code.
 +https://docs.gitlab.com/ee/ci/yaml/yaml_optimization.html#reference-tags
 +
 +Use the !reference custom YAML tag to select keyword configuration from other job sections and reuse it in the current section. 
 +
 +Unlike YAML anchors, you can use `!reference` tags to reuse configuration from included configuration files as well.
 +
 +
 +setup.yml
 +
 +<sxh yaml>
 +
 +.setup:
 +  script:
 +    - echo creating environment
 +
 +</sxh>
 +
 +
 +gitlab-ci.yml
 +<sxh yaml>
 +include:
 +  - local: setup.yml
 +
 +.teardown:
 +  after_script:
 +    - echo deleting environment
 +
 + 
 +test:
 +  script:
 +    - !reference [.setup, script]
 +    - echo running my own command
 +  after_script:
 +    - !reference [.teardown, after_script]
 +
 +</sxh>
  
gitlabci.1663856347.txt.gz · Last modified: by skipidar