User Tools

Site Tools


gitlabci

Differences

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

Link to this comparison view

Next revision
Previous revision
gitlabci [2021/07/12 10:29] – created skipidargitlabci [2022/09/22 16:35] (current) skipidar
Line 2: Line 2:
  
 .gitlab-ci.yml .gitlab-ci.yml
-<code>+ 
 +<sxh yaml>
 stages: stages:
   - deployless-test   - deployless-test
Line 85: Line 86:
     include: .gitlab-ci-deployto.yml     include: .gitlab-ci-deployto.yml
     strategy: depend     strategy: depend
-</code>+</sxh>
  
  
 .gitlab-ci-test-deployless.yml .gitlab-ci-test-deployless.yml
-<code>+<sxh yaml>
 # no reason to run on launch-hub runner. Only required, when assuming IAM roles into the account. # no reason to run on launch-hub runner. Only required, when assuming IAM roles into the account.
  
Line 167: Line 168:
     - echo "This job does UI tests on STAGE."     - echo "This job does UI tests on STAGE."
  
-</code>+</sxh> 
 + 
 + 
 +=== hide a job (.job) === 
 +Start the job name with a dot (.) and it is not processed by GitLab CI/CD 
 +https://docs.gitlab.com/ee/ci/jobs/#hide-jobs 
 + 
 +<sxh yaml> 
 + .terraform_image: &terraform_image 
 +   name: hashicorp/terraform:light 
 +   entrypoint: 
 +     - '/usr/bin/env' 
 +     - 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' 
 +</sxh> 
 + 
 + 
 +=== includes of another files === 
 + 
 +You can include 
 + - from a subfolder 
 + - from another gitlab-repository using "project" syntax 
 + 
 +<sxh yaml> 
 +include: 
 +  - gitlab_pipeline_jobs/shared.yml 
 +  - gitlab_pipeline_jobs/deployment.yml 
 +  - project: "mygroup/pipeline/autodevops" 
 +    ref: master 
 +    file: "templates/pipeline-cypress.yml" 
 +</sxh> 
 + 
 + 
 + 
 + 
 +=== extends: syntax === 
 +You can use the ".extends" mechanism to refer to included modules, 
 +when the included modules shouldnt be activated automatically. 
 + 
 +Instead you should include those with customized variables. 
 + 
 +https://docs.gitlab.com/ee/ci/yaml/#extends 
 + 
 +<sxh yaml> 
 +.tests: 
 +  script: rake test 
 +  stage: test 
 +  only: 
 +    refs: 
 +      - branches 
 + 
 +rspec: 
 +  extends: .tests 
 +  script: rake rspec 
 +  only: 
 +    variables: 
 +      - $RSPEC 
 +</sxh> 
 + 
 + 
 +=== 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.1626085763.txt.gz · Last modified: by skipidar