Execute final step with build result

Hi TeamCity community,

I'm trying to configure a final step in TeamCity which will run a script that will post information about the build to a third-part platform.

I need to pass these information:

  • duration (could potentially add a step at the very beggining which save the start time in an env variable)
  • exit code or success/failure
  • build log

This step will be executed even if preceding steps failed.

How do I access those information? There is any variable I could use?

Thank you,

Egidio

0
1 comment

Hi Egidio,

Unfortunately, no variables for this 3 parameters are exposed. There might be ways to get them, though.

Duration is not available through the build, because it hasn't finished. TeamCity does register the start date of a build, so it should be possible to calculate the duration by obtaining the starting time of the build. For this, you can either set up your own plugin, or, after the build has finished, you can get it from the REST API: http://<url>/app/rest/builds/id:<id>/?fields=startDate,status (also includes status for SUCCESS/FAILURE)

A plugin mentioned here: http://stackoverflow.com/questions/7019954/teamcity-current-date-variable-in-mmdd-format exposes the start date and time.

The build log can be retrieved through https://confluence.jetbrains.com/display/TCD10/Build+Log#BuildLog-downloadBuildLog.

Exit code would be more complicated. You can either shift through it with the build log, or create your own plugin, or a command line runner that wraps and exposes the exit code. Success / Failure can be easily obtained from the REST API (indicated above)

Also take into account for exit code that a multi-step configuration will have multiple exit codes (one for each step). Multiple process can be spawned so a single exit code for the build might not apply at all.

0

Please sign in to leave a comment.