I have a 4 jobs in my .gitlab-ci.yml
file. A lot of the code from before_script
part in every job is this same. I was thinking of taking the part that repeat and place it in some kind of "function" so I can just "call it" in different jobs. Is that possible?
I was also thinking to split those jobs into seperate .yml
files and then "call" this common part in all of those files. Possible?
Possible!
Just use include key word in gitlab-ci.yml
It let's you to 'import' another .yml, so it is possible to reuse same .yml code in many places.
Moreover, you can import for example one job and override some of its attributes, like variables.
It is really flexible.
Please see: https://docs.gitlab.com/ci/yaml/includes/
Have fun 😎