0

I am looking for a way to make a multiline script like:

steps:
  - script: >
      echo foo
      bar

result in:

foobar

with no spaces or newlines.


In the real-world scenario I am defining a variable like so:

  - script: >
      echo
      "##vso[task.setvariable variable=packageVersion]
      some_very_long_awk_code_to_generate_a_3_digit_number"

This issue is causing it to include a space, so the stored variable will become some_very_... (note the space at the start). The ">" next to the script will add spaces where there are newlines, but there seems to be no method to just join it without a space or newline.

This explanation about YAML multiline code explains that it should work as follows:

steps:
  - script: >
      echo foo\
      bar

Unfortunately, this also results in:

foo bar

Performing it with a double quote:

steps:
  - script: >
      echo "foo\
      bar"

will result in:

foo\ bar
Siete
  • 328
  • 3
  • 14

1 Answers1

0

Azure-pipelines - script: ... does not support multiline code with no spaces and no newlines

The document about YAML multiline code is used for parameter, but this doesn't work in the output syntax echo.

And when you create a default YAML pipeline with Starter piepline:

enter image description here

There is a demo code about multi-line script:

steps:

- script: |
    echo Add other tasks to build, test, and deploy your project.
    echo See https://aka.ms/yaml
  displayName: 'Run a multi-line script'

So, if you want make a multiline script, you could try to use below scripts:

- script: |
    echo foo
    echo bar
Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Thanks, I will take a look at the demo. So 'parameters' are parsed different then 'script' content? It's all YAML right? So how can you make it combine multiline script without a newline or space? The example you give at the end simple executes both, but what I want to see is "fooecho bar" to be returned. – Siete Jun 03 '22 at 12:59
  • @Siete, You could use `- script: | echo echofoo echo bar` – Leo Liu Jun 06 '22 at 01:33
  • Looking back at this, I think I phrased my question incorrectly. What I am looking for is breaking a very long line of code with no spaces, into multiple lines for readability. But any newline I add will result in a space when the `- script:` input is parsed. – Siete Dec 20 '22 at 10:45