3

Is it possible in the azure pipeline to pass a multi-line parameter? If type is a string, you can't even write with a newline. If on the other hand the type is object, you can enter multi-line, but all EOLs in the variable will be removed.

parameters:
- name: Multiline
  type: object

enter image description here

If I save the parameter to a text file, the result is one-line

- bash: |
    echo ${{ parameters.Multiline }} >> script.txt
    cat script.txt

enter image description here

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
Rozmaryn
  • 251
  • 1
  • 5
  • 10

2 Answers2

3

I think multiline parameters are not supported natively but you can use object to pass a multiline string. The way it can be done is by adding a yaml object that will contain the multiline string:

eg.

foo: |
  Multiline
  text
  in 
  parameter

Then you can access foo by writing ${{ parameters.Multiline.foo }}.

This is the pipeline code:

parameters:
- name: Multiline
  type: object
  
pool:
  vmImage: 'ubuntu-latest'

steps:
  - bash: |
      cat >> script.txt << EOL
      ${{ parameters.Multiline.foo }}
      EOL
        
      cat script.txt
Murli Prajapati
  • 8,833
  • 5
  • 38
  • 55
  • Can parameters be one line with type on the same line? Or more compact, line wise? – Rod Mar 19 '23 at 15:37
  • DevOps complains that I am not passing the Multiline parameter when it parses the pipeline and template. In the pipeline I have a parameter called foo, but the template is expecting a parameter called Multiline. Whant am I missing here? – Joe Brinkman Jun 30 '23 at 15:59
0

Not sure on the original use case, but here's how you can do this when passing a parameter to a template, using the pipe | syntax.

print-string-to-file.yml

# Prints a string to a file then prints the contents of the file
parameters:
  - name: string_to_print
    type: string

steps:
  - script: |
      cat >> output.txt << EOL
      ${{ parameters.string_to_print }}
      EOL
      
      cat output.txt

pipeline.yml

# Demonstrates how to pass a multi-line string to a template.
pool:
  vmImage: 'ubuntu-latest'

stages:
  - stage:
    jobs:
      - job: print_file_contents
        steps:
        - template: print-string-to-file.yml
          parameters:
            string_to_print: |
              Hello world!
              This parameter contains a string
              which spreads over multiple lines.
              Can ADO parameters handle it?

Log output:

Hello world!
This file contains lots of strings.
Representing different bits of data.
Can ADO parameters handle them all?
Xeozim
  • 53
  • 5