3

I know that one can output messages to TeamCity build logs via specially decorated Write-Host:

write-host "##teamcity[message text='Prepearing backup folder']" 

What if I need the message to contain a value of a variable as well.

I've tried the following:

$myFullMessage = "Perpearing backup folder at: " + $path
write-host "##teamcity[message text=$myFullMessage]" 

But I get an error in an output stating that the message parameter provided should start with ' character.

Please let me know if I can output messages with variable value part in message body.

Maxim V. Pavlov
  • 10,303
  • 17
  • 74
  • 174

1 Answers1

12

The easiest way is a string formatter. Otherwise you get in escape-character hell. Note how in Powershell that you must place two consecutive single-quote characters to put a literal one in the string.

$myFullMessage = "Perpearing backup folder at: " + $path
write-host $( '##teamcity[message text=''{0}'']' -f $myFullMessage ) 
Eris
  • 7,378
  • 1
  • 30
  • 45