I have an unity ci-project. .gitlab-ci.yml
contains base .build
job with one script
command. Also I have multiple specified jobs for build each platform which extended base .build
. I want to execute some platform-specific commands for android, so I have created separated job generate-android-apk
. But if it's failing the pipeline will be failed too.(I know about allow_failure
). Is it possible to extend script
section between jobs without copy-pasting?
Here is the definition from GitLab documentation: extends defines entry names that a job that uses extends inherits from. It's an alternative to using YAML anchors and is a little more flexible and readable.
These are scripts that you choose to be run before the job is executed or after the job is executed. These can also be defined at the top level of the YAML file (where jobs are defined) and they'll apply to all jobs in the . gitlab-ci. yml file.
There are three main ways to structure your pipelines, each with their own advantages. These methods can be mixed and matched if needed: Basic: Good for straightforward projects where all the configuration is in one easy to find place.
If you have access project A and B, you can use multi-project pipelines. You trigger a pipeline in project A from project B. In project A, you clone project B and run your script.
UPDATE:
since gitlab 13.9 it is possible to use !reference
tags from other jobs or "templates" (which are commented jobs - using dot as prefix)
actual_job: script: - echo doing something .template_job: after_script: - echo done with something job_using_references_from_other_jobs: script: - !reference [actual_job, script] after_script: - !reference [template_job, after_script]
Thanks to @amine-zaine for the update
FIRST APPROACH:
You can achieve modular script sections by utilizing 'literal blocks' (using |) like so:
.template1: &template1 | echo install .template2: &template2 | echo bundle testJob: script: - *template1 - *template2
See Source
ANOTHER SOLUTION:
Since GitLab 11.3 it is possible to use extend
which could also work for you.
.template: script: echo test template stage: testStage only: refs: - branches rspec: extends: .template1 after_script: - echo test job only: variables: - $TestVar
See Docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With