Hello,
I’m converting my configuration from YAML to Starlark and I’ve encountered an issue with multiline strings.
In YAML I have the following pipeline step:
- name: check
image: alpine
pull: if-not-exists
commands:
- |
if ! echo ${DRONE_COMMIT_MESSAGE} | grep -q ${DRONE_STAGE_NAME}; then
echo ${DRONE_STAGE_NAME} build not required
exit 78
fi
…and I’m trying to write it in Starlark as:
return {
'name': 'check',
'image': 'alpine',
'pull': 'if-not-exists',
'commands': '''|
if ! echo ${DRONE_COMMIT_MESSAGE} | grep -q ${DRONE_STAGE_NAME}; then
echo ${DRONE_STAGE_NAME} build not required
exit 78
fi'''
}
This fails with a generic error when attempting to convert it to YAML:
$ drone starlark convert --stdout
yaml: unmarshal errors:
line 1: cannot unmarshal !!str `|
...` into []string
I’ve tried various combinations of strings and escaping newlines, but none worked. If I run with --format=false
, some output gets produced:
$ drone starlark convert --stdout --format=false
---
{"kind": "pipeline", "type": "docker", "name": "ctags", "platform": {"arch": "arm64", "os": "linux"}, "steps": [{"name": "submodule", "image": "plugins/git", "pull": "if-not-exists", "commands": ["git submodule update --init ${DRONE_STAGE_NAME%%-*}"]}, {"name": "check", "image": "alpine", "pull": "if-not-exists", "commands": "|\n if ! echo ${DRONE_COMMIT_MESSAGE} | grep -q ${DRONE_STAGE_NAME}; then\n echo ${DRONE_STAGE_NAME} build not required\n exit 78\n fi"}]}
Is this a bug, or am I writing the multiline command in Starlark wrong?
Thank you.