Coder Social home page Coder Social logo

Comments (5)

Super8film87 avatar Super8film87 commented on June 11, 2024 1

Thx for the fast feedback - Perfect that helps already a lot.

from tcwebhooks.

netwolfuk avatar netwolfuk commented on June 11, 2024

Hi @Super8film87 You've made some good progress. You might realise that the $build object in the template is an SBuild object. There are a few versions of this interface, but for the BuildFinished events (Success, Failed, Fixed, Broken) the $build will be an SFinishedBuild.

In velocity, calling $build.startDate will call the getStartDate() method on the SFinishedBuild object.

getStateDate() returns a java.util.Date, and you can then call getTime() on it, which returns milliseconds since epoch.

So, I was able to get queue duration like this..

#set($queueDuration = (${build.StartDate.Time} - ${build.QueuedDate.Time}) /1000)
#set($buildDuration = (${build.FinishDate.Time} - ${build.StartDate.Time}) /1000)
{ 
    "queueTime" : "$queueDuration seconds",
    "buildTime" : "$buildDuration seconds",
}

which outputs...

{ 
    "queueTime" : "4 seconds",
    "buildTime" : "340 seconds",
}

I have not figured out how to get at the Build Steps.

from tcwebhooks.

netwolfuk avatar netwolfuk commented on June 11, 2024

I've asked the team.
https://youtrack.jetbrains.com/issue/TW-81941/How-to-access-Build-Steps-from-OpenAPI-plugin

from tcwebhooks.

netwolfuk avatar netwolfuk commented on June 11, 2024

Hi @Super8film87

The team at Jetbrains answered the query. Here is a working template that now includes step name and duration.

## Define macro called "getFirstFailedBuild"
#macro( getFirstFailedBuild $myBuild)
  #set ($currentBuild = $myBuild)
  #set ($previousBuild = $myBuild.getPreviousFinished())
  #set ($keepLooping = true)
  #foreach($unused in [1..50]) ## only loop 50 times in case there are hundreds of failures
    #if ($keepLooping)
      #if ($previousBuild) ## Null check 
        #if ($previousBuild.getStatusDescriptor().isSuccessful())
          #set ($keepLooping = false) ## Our $previousBuild is isSuccessful, so the $currentBuild is the last failure
          "$currentBuild.buildNumber :: $currentBuild.getStatusDescriptor().isSuccessful()" ## Output something when we find out first failure
        #end
      #else
         #set ($keepLooping = false)
         "unknown" ## text to display if getPreviousFinished returns null
      #end
      #set ($currentBuild = $previousBuild) ## set vars for next iteration
      #set ($previousBuild = $previousBuild.getPreviousFinished()) ## set vars for next iteration
    #end ## close $keepLooping
  #end
#end

#set($queueDuration = (${build.StartDate.Time} - ${build.QueuedDate.Time}) /1000)
#set($buildDuration = (${build.FinishDate.Time} - ${build.StartDate.Time}) /1000)
{ 
    "queueTime" : "$queueDuration seconds",
    "buildTime" : "$buildDuration seconds",
    "firstFailed" : #getFirstFailedBuild($build)
    "steps" :[
        #foreach($buildStep in $build.getBuildPromotion().getBuildSettings().getBuildRunners())
        #set($stepDuration = ($build.getStatisticValue("buildStageDuration:buildStep" + $buildStep.getId())) /1000)
        {
            "stepName" : "$buildStep.getName()",
            "buildStepDuration" : "$stepDuration seconds"
        },
        #end
    ]
}

For me, I get the following when run against a build with steps.

{ 
    "queueTime" : "337 seconds",
    "buildTime" : "360 seconds",
    "firstFailed" :              "908 :: true"                                                                                                      
    "steps" :[
        {
            "stepName" : "Build and Package - Maven",
            "buildStepDuration" : "244.713000 seconds"
        },
        {
            "stepName" : "SonarQube Runner",
            "buildStepDuration" : "110.644000 seconds"
        },
    ]
}

The list of values that can be used to get a statistic are on your build in the REST API.
http://teamcity:8111/app/rest/builds/id:150414/statistics

The id value is the internal build number. It's in the URL when you view a specific build.

from tcwebhooks.

Super8film87 avatar Super8film87 commented on June 11, 2024

Cool - will test it. Thx for the support

from tcwebhooks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.