Search code examples
azure-devopsparametersazure-pipelinespipelinemultiline

Azure Pipelines: multiline parameter


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


Solution

  • 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