Using ":" in bitbucket pipelines

Hamdi Fourati February 4, 2019

Hello,

I'm wondering why bitbucket pipelines are parsing stings inside the script section.

image: ubuntu:18.04

pipelines:
  default:
    - step:
      script:
        -  echo "Echo from pipelines : ${MY_VAR}"

 

This is not valid because of the ":" !!

2 answers

1 accepted

6 votes
Answer accepted
Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 4, 2019

Hi Hamdi,

The colon character is causing the particular line you have to be parsed as a map instead of a string. This is part of the YAML specification, which the bitbucket-pipelines.yml file follows. Specifically, a colon followed by a space will make the entire line interpreted as a map instead of a string.

There are a few ways to work around this, which will all make the line be interpreted as a string instead.

1. Remove the space after the colon

image: ubuntu:18.04

pipelines:
  default:
    - step:
      script:
        -  echo "Echo from pipelines :${MY_VAR}"

2. Escape the space after the colon

image: ubuntu:18.04

pipelines:
  default:
    - step:
      script:
        -  echo "Echo from pipelines :\ ${MY_VAR}"

3. Quote the entire command line, which will indicate the line is a string.

image: ubuntu:18.04

pipelines:
  default:
    - step:
      script:
        -  'echo "Echo from pipelines : ${MY_VAR}"'

4. Quote the colon character

image: ubuntu:18.04

pipelines:
  default:
    - step:
      script:
        -  echo "Echo from pipelines ':' ${MY_VAR}"


Thanks,

Phil

Hamdi Fourati February 5, 2019

Hello Phil,

Thank you for the answer.

rgbp February 13, 2020

For me, only the option 3 works since I was using 'echo -e'.

Thanks

Like Tuomas Tikkanen likes this
0 votes
Pavel Shanaev May 14, 2020

The php-codeception uses an option string like a YAML-syntax:

 ./vendor/bin/codecept run --override="paths: output: ./test-reports"

 Colons and unquoted spaces are mandatory. 
The only way I have found is:

pipelines:
  default:
    - step:
      script:
- printf './vendor/bin/codecept run --override="paths\x3a output\x3a ./test-reports"' | sh -

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events