Evgeny Goldin works as a Technical Evangelist for the JetBrains TeamCity CI build server. He speaks Java, JavaScript, Perl and Groovy. His favorite products are MediaWiki, Intellij IDEA, Git, Artifactory, Gradle, YouTrack and TeamCity. He enjoys driving, learning and solving challenging problems. He doesn't like wasting time and being unproductive and believes that simplicity, attention to details and tidy working environments are the most efficient approaches to successful delivery. Evgeny is a DZone MVB and is not an employee of DZone and has posted 17 posts at DZone. You can read more from them at their website. View Full User Profile

Maven Build Progress With TeamCity Service Messages

05.26.2012
| 2920 views |
  • submit to reddit
When you run a lengthy Maven build configuration in TeamCity it may be tricky to know what module is being built right now since all TeamCity displays is either “Running” or “Tests passed: X”.

Luckily, TeamCity allows your build script to interact with the server using Service Messages. When you build script prints out the following command, TeamCity reads it and behaves accordingly.

This way it is possible to report a compilation or testing results, publish artifacts (you can find "##teamcity[publishArtifacts" messages in IntelliJ IDEA build log), and even update build parameters on the fly. However, what I was interested in is build progress report:

Adding a single println to a Maven build can be done with a bit of Groovy scripting:

<plugin>
  <groupId>org.codehaus.gmaven</groupId>
  <artifactId>gmaven-plugin</artifactId>
  <version>1.4</version>
  <executions>
    <execution>
      <id>display-progress-report</id>
      <phase>initialize</phase>
      <goals>
        <goal>execute</goal>
      </goals>
      <configuration>
        <providerSelection>1.8</providerSelection>
        <source>
        if ( System.getProperty( 'teamcity.version' ))
        {
          println "##teamcity[progressMessage '${project.groupId}:${project.artifactId}']"
        }
        </source>
      </configuration>
    </execution>
  </executions>
</plugin>

After adding this snippet to project's parent POM, the progress indicator becomes (see it live!)

And I'm now working on making this functionality built-in for TeamCity 7.1.

Same trick can be used in Gradle, but it is less required since TeamCity already reports Gradle tasks progress. Anyway, if you're interested, grab this code:

allprojects {
    ...
    if ( project.properties.teamcity )
    {
        tasks.all { it.doFirst {
            logger.lifecycle( "##teamcity[progressMessage ':${project.name}:${it.name}']" )
        }}
    }
    ...
}
Published at DZone with permission of Evgeny Goldin, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)