Get content from text file and save it into a variable - Azure YML

Copper Contributor

I have a txt file and I'm trying to save all the content in a variable but I'm only getting the first line of the content into the variable



- hello: 123 
- hello: 456
- hello: 789 


- name: MY_TEXT_FILE
  value: 'greetings.txt'
  readonly: true

# Save text file content in this variable
  value: ''

    - task: Bash@3
      displayName: 'Save text file content in a variable'
        targetType: 'inline'
        script: |
                      echo "##vso[task.setvariable variable=GREETINGS_CONTENT]$(cat $MY_TEXT_FILE)"
- task: Bash@3 displayName: 'Another task' inputs: targetType: inline script: | # This is only printing the first line of the txt file # I want to save ALL the txt file content in the variable echo "My greetings are: $GREETINGS_CONTENT"

Results after 'Another task' is executed:

Actual results:

- hello: 123

Expected results:

- hello: 123 
- hello: 456
- hello: 789

What I need to update so I can get the expected results?

0 Replies