'Script command using ":" causing error in .gitlab-ci.yml execution
Below my .gitlab-ci.yml
file:
image: docker:latest
services:
- docker:dind
stages:
- deploy_dev_env
Deploy DEV Environment:
stage: deploy_dev_env
script:
- curl -v -H "Content-Type: multipart/form-data" -X PUT -F uploadInput=@schema/schema.xml -F overwrite=true -F xmlaEnabledFlag=true -F parameters="DataSource=outputDS" -F parameters="EnableXmla=true" -u $PENTAHO_DEPLOY_USER:$PENTAHO_DEPLOY_PASSWORD http://$PENTAHO_HOST/pentaho/plugin/data-access/api/datasource/analysis/catalog/sca
This very simple script is causing an error because the colons(:) in the "Content-Type: multipart/form-data"
piece.
Running the CI Lint in the script I get the following:
Status: syntax is incorrect
jobs:deploy dev environment:script config should be a string or an array containing strings and arrays of strings
If I replace "Content-Type: multipart/form-data"
by "Content-Type multipart/form-data"
(removed the ":"), I get I correct syntax for my .gitlab-ci.yml file.
Is this a bug or should I re-write my curl command in a different way ?
Solution 1:[1]
Docs warn about special characters in yaml script:
Note: Sometimes, script commands will need to be wrapped in single or double quotes. For example, commands that contain a colon (:) need to be wrapped in quotes so that the YAML parser knows to interpret the whole thing as a string rather than a “key: value” pair. Be careful when using special characters: :, {, }, [, ], ,, &, *, #, ?, |, -, <, >, =, !, %, @, `.
One of the option would be to use yaml block scalar
Deploy DEV Environment:
stage: deploy_dev_env
script: >
curl -v -H "Content-Type: multipart/form-data" -X PUT -F uploadInput=@schema/schema.xml -F overwrite=true -F xmlaEnabledFlag=true -F parameters="DataSource=outputDS" -F parameters="EnableXmla=true" -u $PENTAHO_DEPLOY_USER:$PENTAHO_DEPLOY_PASSWORD http://$PENTAHO_HOST/pentaho/plugin/data-access/api/datasource/analysis/catalog/sca
or use some other way to escape colon in yaml.
Solution 2:[2]
I faced this issue due to yaml syntax before and the workaround i found was
Store the "Content-Type: application/json" as an environment variable in the CICD settings for example
Key: HEADER
Value: Content-Type: application/json
and in your script
- curl -v -H "$HEADER" -X PUT -F uploadInput=@schema/schema.xml -F overwrite=true -F xmlaEnabledFlag=true -F parameters="DataSource=outputDS" -F parameters="EnableXmla=true" -u $PENTAHO_DEPLOY_USER:$PENTAHO_DEPLOY_PASSWORD http://$PENTAHO_HOST/pentaho/plugin/data-access/api/datasource/analysis/catalog/sca
Solution 3:[3]
After going through several options, I found below simple solution Use like this,
Content_Type="Content-Type:" export RESULT="$(echo "$Content_Type" multipart/form-data)" echo "Result is " $RESULT
Use $RESULT as variable there
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Ghonima |
Solution 3 |