Get build failure error message using teamcity in build step

Hi ,

we have functionality to get the build failure error message through the build notification which is logged by build ruuner by default. but I want to get the error message in build step which can be command line or Powershell.

By default notification we can get the build log using { build.buildLog.messages[1..] as message }. but I have created a custom configuration that I want to use to write-host that error message when the build failed due to any reason.

Any suggestions on things I should check?  Thanks!

Thanks in advance.

7 comments
Comment actions Permalink

Hi Sunil,

If you want to report messages for a build log, you can use service messages. For example, to fail Command Line build step use the folloing message:
echo "

##teamcity[message text='Exception text'
 
errorDetails='stack trace'
 
status='ERROR']
"
Please note that "Fail build if an error message is logged by build runner" box should be checked on the Build Failure Conditions page of a build configuration.
0
Comment actions Permalink

Thanks Alina for your suggestions.

I have point that at provided link the block contains the following details.

Reporting Messages For Build Log

You can report messages for a build log in the following way:

##teamcity[message text='<message text>' errorDetails='<error details>' status='<status value>']

where:

  • The
    status
    attribute may take following values:
    NORMAL
    ,
    WARNING
    ,
    FAILURE
    ,
    ERROR
    . The default value is
    NORMAL
    .
  • The
    errorDetails
    attribute is used only if
    status
    is
    ERROR
    , in other cases it is ignored.

This message fails the build in case its status is

ERROR
and "Fail build if an error message is logged by build runner" box is checked on the Build Failure Conditions page of a build configuration. For example:
##teamcity[message text='Exception text' errorDetails='stack trace' status='ERROR']



But As I know this is only use to write their own custom errors in build logs. Build logs will contain the message whatever you mentioned in the
errorDetails='your custom message'. I have used this in my build configuration but after failure it shows below logs only.


Logs.png

But with respect to your valuable time I want to get the error log which is originally occured when my source code compilation failed.

Thanks in advance !!
0
Comment actions Permalink

Could you please describe your use case in more details? What type of runner do you use? Please provide the current build log and what you expect to have in the build log.

0
Comment actions Permalink

Thanks again for your response..

I have a Project Build configuration which compile a Utilities project made in C# Dot Net. See the attached screen shot. This configuration have one more step which have only label that will print that Compilation has done .

After this configuration is over then it will start the new configuration build by dependency and here I want to check that previous configuration label have what value ( Set from the first configuration ). If I found a false value then it is sure that compilation of previous project is false. So I need to get that compilation error here which occurred at the time of previous configuration build run.



Attachment(s):
DB.png
0
Comment actions Permalink

From within the build script you can use REST API to get the build status and statusText based on the build id which you can reference via %dep.XXX.teamcity.build.id% reference in a parameter. Please vote for the related request in our tracker: https://youtrack.jetbrains.com/issue/TW-20776.

0
Comment actions Permalink

Thanks Alina for your support so far.

Let pointing to the exact thing what I needed. I have used these type of status text , users in two build changes, no of files between checkins although using the REST API in my dependency build configuration.

It will be good if there is any way to get the errors message of parent configuration in child configuration. That's it from my side.


Thanks if you can provide any further info.

0
Comment actions Permalink

Alina,

Did you get change to look on this further ?

0

Please sign in to leave a comment.