Handling commit messages with a quote character
Sometimes it is necessary to use commit messages to decide the logical flow of a pipeline. One such example is skipping continuous integration if the commit message contains “–skip-ci”.
Example:
YAML
build_step:
type: build
image_name: codefreshio/yaml-example-unit-test-compose
dockerfile: Dockerfile
tag: ${{CF_BRANCH}}
when:
condition:
all:
noSkipCiInCommitMessage: 'includes(lower("${{CF_COMMIT_MESSAGE}}"), "--skip-ci") == false'
However, doing this might cause the following error if the commit message contains a quote character:
Error parsing YAML file: can not read a block mapping entry; a multiline key may not be an implicit key at line 13, column 30
As explained, this is a string quoting issue. The commit message uses a ‘ symbol, as does the YAML file itself to denote string. This breaks the YAML file. The solution is to use a multi-line string.
YAML
build_step:
type: build
image_name: codefreshio/yaml-example-unit-test-compose
dockerfile: Dockerfile
tag: ${{CF_BRANCH}}
when:
condition:
all:
noSkipCiInCommitMessage: |
includes(lower("${{CF_COMMIT_MESSAGE}}"), "--skip-ci") == false