0

I want every command ran from a bash script to be echoed with the custom prefix of ##[command]. This has a meaning when the script is run from Azure Pipelines.

For example, when running ls -l from such a script I would like to see something like this:

##[command]ls -l
total 20
-rw-r--r-- 1 mark mark 2447 Nov 14 23:56 1.txt
-rw-r--r-- 1 mark mark 1533 Nov 14 23:56 2.txt
-rw-r--r-- 1 mark mark 1545 Nov 14 23:56 3.txt
-rw-r--r-- 1 mark mark 6918 Nov 14 23:56 4.txt

The solution could be something automatic or some kind of a function, which could be invoked like this: run('ls -l').

Using a function means there would be a special step in every build job to ensure this function is defined in the .bashrc script, so that subsequent steps could see it. At least, this is what I think, not sure if bash steps load the .bashrc script at all.

Anyway, the solution should be applicable to multiple steps in an Azure Pipeline YAML without a lot of overhead.

1 Answer 1

1

I suggest to use with bash:

PS4="##[command]"; set -x

Sign up to request clarification or add additional context in comments.

1 Comment

That works beautifully. The only minor issue is that it does not log redirection. But it is good enough for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.