0

I can do this

- var=`<some command>`

but the command I want is too long and contains pipes so I would like to write it on separate lines like this:

- var=`<command>

  -arg1 value1

  -arg2 value2

 | awk '{print $2}' ...

`

but that doesn't work.

Hussein Hijazi
  • 439
  • 4
  • 13
  • What exactly is the problem you are experiencing? Does the bitbucket-pipelines.yaml editor give you an error message or do you get an error actually running the command? Could you post the whole step definition thats causing problems? – Max Binnewies Mar 02 '20 at 01:01

1 Answers1

1

Multi-line YML commands

The YML syntax supports steps that have multiple lines. Just start the step with "- |" and indent it 2 columns further. See example from here: How can I start and stop a background task on travis?

- |
  # This is a comment in the multi-line block
  if [ "$TEST_ADAPTER" = "HTTP" ]; then
    vendor/bin/httpd.php&
    SERVER_PID=$!

  # Blank lines are also supported
  fi

Call a bash script from YML

You can also call an external shell script from the YML file. This script can contain multiple lines:

- chmod +x my_script.sh # Make the script executable, if necessary
- ./my_script.sh # Run the external script
- bash ./my_script.sh # Run the external script

Wrap long lines in shell scripts or YML commands

Both YML and shell scripts support wrapping long lines with the backslash "\" character at the end of the line. They are called bash continuation lines, and described here Bash continuation lines . Here's an example:

printf '%s' \
    "This will all be printed on a " \
    "single line (because the format string " \
    "doesn't specify any newline)"
Mr-IDE
  • 7,051
  • 1
  • 53
  • 59