Allow both global and step-specific before_script to work when using 'extends'
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Problem to solve
Customer-requested proposal:
I need to be able to have a global before_script and a step-specific before_script that both run in that specific step. Currently a before_script that is declared in a step overwrites the before_script that is declared globally. This is not good behaviour as there are good reasons to have a global and a local before_script. For example (and this is the problem I'm trying to solve): A global before_script is tasked with searching-and-replacing version numbers in code. The step-specific before_script is tasked with logging into a container-registry.
I am using 'include' to include build-steps from a centralised-repo. This has worked fine for all projects except those that have a before_script declared in their ci-file. To get around that I tried using yaml-anchors (doesn't work because it has to be in the same yaml-file) and the 'extends' keyword. Using the extends keyword does not throw a yaml-error but since 'before_script' and 'script' are overwritten in each step the 'before_script'/'script' declared in the yml from 'extends' does not run.
I realise that the yaml-loader is clearly not adding the scripts to an array (as I would like it to do) but instead overwriting the script, if it exists, in each step. I need a way around this bug/lack of functionality.
Example:
stages:
- build
.write_version:
script:
- echo "aaaa"
include:
- project: foo
ref: master
file: build.yml
# build.yml (project: foo)
buildbar:
extends: .write_version
script:
- echo "bbbb"
The above example only runs echo "bbbb" while I need to run both commands. This example is the same for 'before_script'
User experience goal
User should be able to utilize before_script when using extends.
Proposal
Allow before_script to work on each script, even when using extends