Define a Job in GitLab CI with a script List
Define a GitLab CI job with script as a list of commands, and quote any command that contains a colon and a space, or YAML turns it into a key and value.
A job's script lists the commands to run, and one of them breaks the pipeline file in a way the log does not explain.
build:
stage: build
script:
- 'echo "build: started"'
- make
- echo build: doneimport yaml
doc = yaml.safe_load("""
build:
stage: build
script:
- 'echo "build: started"'
- make
- echo build: done
""")
for line in doc["build"]["script"]:
print(repr(line))'echo "build: started"'
'make'
{'echo build': 'done'}Each item under script is a command run by the job's shell. A YAML plain scalar that contains a colon followed by a space is read as a mapping. The unquoted echo build: done became {'echo build': 'done'}, not a command, while the same text wrapped in single quotes stayed a string, even with double quotes inside. The run prints all three items so you can see which one is a command. See script in the GitLab documentation.
Quote any command that has a colon and a space, or a leading *, &, !, { or [. A linter such as the CI Lint page in GitLab flags the problem before you commit. The parser used here is PyYAML, and GitLab uses its own, but the YAML rule is the same.