Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 3
Message 1 of 4

set-output Truncates Multiline Strings

Solved! Go to Solution.

Hi,

 

I am using this code to create a release for one of our repositories:

      - shell: bash
        id: release_description
        run: |
          description=$(./resources/get_release_description.sh ${{ steps.versioning.outputs.cli_version }})
          echo $description
          echo "::set-output name=description::$description"
        if: startsWith(steps.commit_message.outputs.commit_message, 'Version change')
      - shell: bash
        run: |
          echo ${{ steps.release_description.outputs.description }}
        if: startsWith(steps.commit_message.outputs.commit_message, 'Version change')
      - uses: csexton/create-release@add-body
        id: create_release
        with:
          tag_name: ${{ steps.versioning.outputs.cli_version }}
          release_name: safe-cli
          draft: false
          prerelease: false
          body: ${{ steps.release_description.outputs.description }}


This works without any errors. However, the problem is, the description (the body parameter of the create_release action) is basically a small markdown document, so it's a multiline string. The problem is that ::set-output is truncating everything except the first line. I can confirm that by echoing the description in the same action where it's assigned and then referencing the description output variable in the next action.

Could someone please advise how I can get this to work with a multiline string?

Thanks. 

3 Replies
GitHub Partner
Message 2 of 4

Re: set-output Truncates Multiline Strings

I have reported your question to the appropriate engineering team for further evaluation. The team will review the feedback and notify me about the next steps. I will update here in time. Thank you for your understanding.

Solution
GitHub Partner
Message 3 of 4

Re: set-output Truncates Multiline Strings

I got response from the team. 

% and \n and \r can be escaped like below, the runner will unescape in reverse.

content="${content//'%'/'%25'}"
content="${content//$'\n'/'%0A'}"
content="${content//$'\r'/'%0D'}"

Please try to add next three red lines to your yml, kindly let me know whether this could help.

- shell: bash
        id: release_description
        run: |
          description=$(./resources/get_release_description.sh ${{ steps.versioning.outputs.cli_version }})
          echo $description
description="${description//'%'/'%25'}" description="${description//$'\n'/'%0A'}" description="${description//$'\r'/'%0D'}"
echo "::set-output name=description::$description"
if: startsWith(steps.commit_message.outputs.commit_message, 'Version change')

 I tested in my side, after adding these lines, I can use echo "${{ steps.release_description.outputs.description1 }}" to output multiple line value. Please pay attention to ""

multiline.png

Copilot Lvl 3
Message 4 of 4

Re: set-output Truncates Multiline Strings

Sorry, I just noticed your reply!

Thanks very much for this, it resolves the issue.