Gitlab CI jobs need to have a unique key
Especially punitive when working with includes from local files or external components, if you have a job that is running for different environments (say staging and production), with the given component:
# my-component.yml
spec:
inputs:
environment:
type: string
---
do-something:
script:
- echo $[[ inputs.environment ]]
the following .gitlab-ci.yml
# .gitlab-ci.yaml
include:
- component: $CI_SERVER_FQDN/my-project/my-component@1.0.0
inputs:
environment: staging
- component: $CI_SERVER_FQDN/my-project/my-component@1.0.0
inputs:
environment: production
will be compiled to
do-something:
script:
- echo "production"
because the key do-something is duplicated across instanciations of the component.
A solution to this is adding the environment key to the name of the job:
# my-component.yml
spec:
inputs:
environment:
type: string
---
do-something:$[[ inputs.environment ]]:
script:
- echo $[[ inputs.environment ]]