How to do CR (Carriage return) in Azure devops logging

Viewed 470

I have a simple yaml script that starts a task:

trigger:
    branches:
      include:
      - '*'
    tags:
      include:
        - '*'
jobs:
  - job: Linux
    pool:
      name: BuildMachineUbuntu
    steps:
      - checkout: self
        clean: false
      - task: CmdLine@1
        inputs:
          filename: 'CI_Build_Linux.sh'

The CI_Build_Linux.sh is a very simple script:

test_str=$'hello\rworld'
echo "$test_str"
exit 0

Now I expected the outcome to be that the logging just printed world. However it prints 2 lines: hello and world.

outcome from azure logging

So as the title says, how do I do CR in Azure? I want to use it as I want to print progress, but not spam the logging, and SetProgress was not what I was looking for.

Edit: I have added the output after running it with system.debug for both Bash and CmdLine

Output from Bash: https://pastebin.com/YHwdHq1k

Output from CmdLine: https://pastebin.com/Mv33GKSk

1 Answers

We can reproduce this issue and we have reported this issue to Developer Community which is our main forum for product feedback, I will follow the ticket and if it has any updates, I will update here.

In addition, due to some issues, I need to update the feedback ticket link next week.

Update1

We have reported this issue to Product group and we could follow this feedback ticket to get the latest news.

Update2

I got a response:

When you print string with '\r' character in you Bash console - '\r' (Carriage Return) just returns your carriage to the start position of string and prints other part starting from this position. It's a behavior of your terminal, not of Bash. Here is a good explanation of this: shell script - BASH and Carriage Return Behavior - Unix & Linux Stack Exchange

When you try to run this code in the Azure Devops pipeline, you have no terminal, just output stream, where all results of Bash commands will go, e.t. first part of line with '\r', and you'll see it in log. I believe that is not bug, and this behavior is designed.

Related