DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Gradle: Modernization of Build Process
  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin
  • How To Approach Dependency Management in Java [Video]
  • How To Add Three Photo Filters to Your Applications in Java

Trending

  • Next.js vs. Gatsby: A Comprehensive Comparison
  • What Technical Skills Can You Expect To Gain From a DevOps Course Syllabus?
  • Breaking Down Silos: The Importance of Collaboration in Solution Architecture
  • Parallel Sort
  1. DZone
  2. Coding
  3. Java
  4. Get TeamCity Artifacts Using HTTP, Ant, Gradle and Maven

Get TeamCity Artifacts Using HTTP, Ant, Gradle and Maven

Evgeny Goldin user avatar by
Evgeny Goldin
·
Jun. 05, 12 · Interview
Like (0)
Save
Tweet
Share
10.03K Views

Join the DZone community and get the full member experience.

Join For Free
In how many ways can you retrieve TeamCity artifacts? I say plenty to choose from! If you’re in a world of Java build tools then you can use plain HTTP request, Ant + Ivy, Gradle and Maven to download and use binaries produced by TeamCity build configurations. How? Read on.

Build Configuration “id”

Before you retrieve artifacts of any build configuration you need to know its "id" which can be seen in a browser when corresponding configuration is browsed. Let’s take IntelliJ IDEA Community Edition project hosted at teamcity.jetbrains.com as an example. Its “Community Dist” build configuration provides a number of artifacts which we’re going to play with. And as can be seen on the screenshot below, its "id" is "bt343".

HTTP

Anonymous HTTP access is probably the easiest way to fetch TeamCity artifacts, the URL to do so is:

http://server/guestAuth/repository/download/<btN>/<buildNumber>/<artifactName>

Fot this request to work 3 parameters need to be specified:

btN Build configuration "id", as mentioned above.
buildNumber Build number or one of predefined constants: "lastSuccessful", "lastPinned", or "lastFinished". For example, you can download periodic IDEA builds from last successful TeamCity execution.
artifactName Name of artifact like "ideaIC-118.SNAPSHOT.win.zip". Can also take a form of "artifactName!archivePath" for reading archive’s content, like IDEA’s build file. You can get a list of all artifacts produced in a certain build by requesting a special "teamcity-ivy.xml" artifact generated by TeamCity.

Ant + Ivy

All artifacts published to TeamCity are accompanied by "teamcity-ivy.xml" Ivy descriptor, effectively making TeamCity an Ivy repository. The code below downloads "core/annotations.jar" from IDEA distribution to "download/ivy" directory:

"ivyconf.xml"

<ivysettings>
    <settings defaultResolver='teamcity-repo'/>
    <resolvers>
        <url name='teamcity-repo' alwaysCheckExactRevision='yes' checkmodified='true'>
            <ivy      pattern='http://teamcity.jetbrains.com/guestAuth/repository/download/[module]/[revision]/teamcity-ivy.xml'/>
            <artifact pattern='http://teamcity.jetbrains.com/guestAuth/repository/download/[module]/[revision]/[artifact](.[ext])'/>
        </url>
    </resolvers>
</ivysettings>

"ivy.xml"

<ivy-module version="1.3">
    <info organisation="com.jetbrains" module="idea"/>
    <dependencies>
        <dependency org="org" name="bt343" rev="lastSuccessful">
            <include name="core/annotations" ext="jar"/>
        </dependency>
    </dependencies>
</ivy-module>

"build.xml"

<project name="teamcity-download" default="download" xmlns:ivy="antlib:org.apache.ivy.ant">
    <target name="download" xmlns:ivy="antlib:org.apache.ivy.ant">
        <taskdef uri="antlib:org.apache.ivy.ant" resource="org/apache/ivy/ant/antlib.xml"/>
        <ivy:configure file    = "${basedir}/ivyconf.xml"/>
        <ivy:resolve   file    = "${basedir}/ivy.xml"/>
        <ivy:retrieve  pattern = "${basedir}/download/ivy/[artifact].[ext]"/>
    </target>
</project>

Gradle

Identically to Ivy example above it is fairly easy to retrieve TeamCity artifacts with Gradle due to its built-in Ivy support. In addition to downloading the same jar file to "download/gradle" directory with a custom Gradle task let’s use it as "compile" dependency for our Java class, importing IDEA’s @NotNull annotation:

"Test.java"

import org.jetbrains.annotations.NotNull;
 
public class Test
{
    private final String data;
    public Test ( @NotNull String data ){ this.data = data; }
}

"build.gradle"

apply plugin: 'java'
 
repositories {
    ivy {
        ivyPattern      'http://teamcity.jetbrains.com/guestAuth/repository/download/[module]/[revision]/teamcity-ivy.xml'
        artifactPattern 'http://teamcity.jetbrains.com/guestAuth/repository/download/[module]/[revision]/[artifact](.[ext])'
    }
}
 
dependencies {
    compile ( 'org:bt343:lastSuccessful' ){
        artifact {
            name = 'core/annotations'
            type = 'jar'
        }
    }
}
 
task copyJar( type: Copy ) {
    from configurations.compile
    into "${ project.projectDir }/download/gradle"
}

Maven

The best way to use Maven with TeamCity is by setting up an Artifactory repository manager and its TeamCity plugin. This way artifacts produced by your builds are nicely deployed to Artifactory and can be served from there as from any other remote Maven repository.

However, you can still use TeamCity artifacts in Maven without any additional setups. "ivy-maven-plugin" bridges two worlds allowing you to plug Ivy resolvers into Maven’s runtime environment, download dependencies required and add them to corresponding "compile" or "test" scopes.

Let’s compile the same Java source from the Gradle example but using Maven this time.

"pom.xml"

<?xml version="1.0" encoding="UTF-8"?>
 
<project xmlns              = "http://maven.apache.org/POM/4.0.0"
         xmlns:xsi          = "http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0
 
http://maven.apache.org/maven-v4_0_0.xsd">
 
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId>
    <artifactId>maven</artifactId>
    <packaging>jar</packaging>
    <version>0.1-SNAPSHOT</version>
    <name>[${project.groupId}:${project.artifactId}:${project.version}]</name>
    <description>Ivy Maven plugin example</description>
 
    <build>
        <plugins>
            <plugin>
                <groupId>com.github.goldin</groupId>
                <artifactId>ivy-maven-plugin</artifactId>
                <version>0.2.5</version>
                <executions>
                    <execution>
                        <id>get-ivy-artifacts</id>
                        <goals>
                            <goal>ivy</goal>
                        </goals>
                        <phase>initialize</phase>
                        <configuration>
                            <ivyconf>${project.basedir}/ivyconf.xml</ivyconf>
                            <ivy>${project.basedir}/ivy.xml</ivy>
                            <dir>${project.basedir}/download/maven</dir>
                            <scope>compile</scope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

When this plugin runs it resolves IDEA annotations artifact using the same "ivyconf.xml" and "ivy.xml" files we’ve seen previously, copies it to "download/maven" directory and adds to "compile" scope so our Java sources can compile.

GitHub Project

All examples demonstrated are available in my GitHub project. Feel free to clone and run it:

git clone git://github.com/evgeny-goldin/teamcity-download-examples.git
cd teamcity-download-examples
chmod +x run.sh dist/ant/bin/ant gradlew dist/maven/bin/mvn
./run.sh

Resources

The links below can provide you with more details:

  • TeamCity – Patterns For Accessing Build Artifacts
  • TeamCity – Accessing Server by HTTP
  • TeamCity – Configuring Artifact Dependencies Using Ant Build Script
  • Gradle – Ivy repositories
  • "ivy-maven-plugin"

That’s it, you’ve seen it – TeamCity artifacts are perfectly accessible using either of 4 ways: direct HTTP access, Ant + Ivy, Gradle or Maven. Which one do you use? Let me know!

 

 

 

 

 

 

 

 

Artifact (UML) TeamCity Apache Maven Gradle intellij Build (game engine)

Published at DZone with permission of Evgeny Goldin, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Gradle: Modernization of Build Process
  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin
  • How To Approach Dependency Management in Java [Video]
  • How To Add Three Photo Filters to Your Applications in Java

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: