Cannot publish artifacts with [] in the file name using service messages

Completed

Hi,

We are trying to publish some logs as build artifacts but are encountering some problems due to the naming convention we use.

In particular, our log files are named as App1.exexxxx-date-[processId].4net.Log. We are getting the list of files to publish using a Powershell script that lists the files, does some additional checking on the files and then prints the publishArtifacts service message for the file.

However, because we have [] as characters in the name, if we attempt to do the following in the script

echo "##teamcity[publishArtifacts 'C:\BuildAgent\work\d8fe71b8f1b901d1\build\Logs\App1.exe11361-2022.07.11.20.30.35-[8896].4net.Log' => BuildLogs.zip]"
 
then we get the following error in the log (seems like it is splitting based on the ] after the processId, as the rest of the filename and the redirect for the artifacts is in a separate line)
    ##teamcity[publishArtifacts 'C:\BuildAgent\work\d8fe71b8f1b901d1\build\Logs\App1.exe11361-2022.07.11.20.30.35-[8896]
    Cannot extract text message ['C:\BuildAgent\work\d8fe71b8f1b901d1\build\Logs\App1.exe11361-2022.07.11.20.30.35-[8896] 
    .4net.Log' => BuildLogs.zip]
 
(Note: text in bold is what is marked in yellow/as a warning in TeamCity)
 
We have attempted also to escape the [ and ] characters using |[ and |] instead 
echo "##teamcity[publishArtifacts 'C:\BuildAgent\work\d8fe71b8f1b901d1\build\Logs\App1.exe11361-2022.07.11.20.30.35-|[8896|].4net.Log' => BuildLogs.zip]"
but that still doesn't work and the log shows the following
   ##teamcity[publishArtifacts 'C:\BuildAgent\work\d8fe71b8f1b901d1\build\Logs\App1.exe11361-2022.07.11.20.30.35-|[8896|].4net.Log' => BuildLogs.zip]
  Cannot extract text message ['C:\BuildAgent\work\d8fe71b8f1b901d1\build\Logs\App1.exe11361-2022.07.11.20.30.35-|[8896|].4net.Log' => BuildLogs.zip]
(Note: text in bold is what is marked in yellow/as a warning in TeamCity)
 
Does the escaping not work for publishArtifacts service message or are we missing some thing in how should we publish the files as artifacts?
 
Using: TeamCity Professional 2022.04.1 (build 108575)
0
2 comments

It is required to escape the [ and ] characters with |[ and |] respectively. However there is another syntax issue in your service message, please try including `=> BuildLogs.zip` in your quotes like this:

echo "##teamcity[publishArtifacts 'C:\BuildAgent\work\d8fe71b8f1b901d1\build\Logs\App1.exe11361-2022.07.11.20.30.35-|[8896|].4net.Log => BuildLogs.zip']" 
0

Oh! That single quote on the wrong place was the trick indeed! Thank you so much!

0

Please sign in to leave a comment.