Configuring Artifact Dependencies
Last modified: 20 April 2023Configuring Artifact Dependencies
A build configuration can be made dependent on the Basic Concepts of builds of some other build configurations. There are two ways to define these Basic Concepts:
Configuring dependencies from the web UI
To add dependencies to a build configuration:
In the Build Configuration Steps, choose Artifact dependencies.
Click Add new dependency link.
In the Artifacts Dependencies, specify the following settings:
Build configuration and build from which artifacts should be taken
Paths to artifacts as they are shown on server
Destination path on agent where to put downloaded artifacts.
Configuring dependencies in Ant build.xml
This way is more complicated but allows greater flexibility. For example, configuring dependencies in this way will allow you to start personal build and verify that your build is still compatible with dependencies.
To configure dependencies in Ant build.xml:
1. Download Ivy from the web site.
tip
TeamCity itself acts as Ivy repository. You can read more about Ivy dependency manager here: http://incubator.apache.org/ivy/.
2. Add Ivy to the classpath of your build. 3. Create ivyconf.xml file that contains some meta information about TeamCity repository. This file should have the following content:
<ivyconf> <property name='ivy.checksums' value=''/> <conf defaultCache="${agent.work.dir}/.ivy/cache"/> <statuses> <status name='lastPinned' integration='false'/> <status name='lastSuccessful' integration='false'/> <status name='lastFinished' integration='false'/> <status name='integration' integration='true'/> </statuses> <resolvers> <url name='teamcity-rep' latest='latest-time'> <ivy pattern='http://YOUR_TEAMCITY_HOST_NAME/repository/download/[module]/[revision]/ivy.xml' /> <artifact pattern='http://YOUR_TEAMCITY_HOST_NAME/repository/download/[module]/[revision]/[artifact](.[ext])' /> </url> </resolvers> <modules> <module organisation='.*' name='.*' matcher='regexp' resolver='teamcity-rep' /> </modules> </ivyconf>
Since 2.1 the config is slightly changed:
<ivyconf> <property name='ivy.checksums' value=''/> <conf defaultCache="${agent.work.dir}/.ivy/cache"/> <statuses> <status name='lastPinned' integration='false'/> <status name='lastSuccessful' integration='false'/> <status name='lastFinished' integration='false'/> <status name='integration' integration='true'/> </statuses> <resolvers> <url name='teamcity-rep' latest='latest-time'> <ivy pattern='http://YOUR_TEAMCITY_HOST_NAME/httpAuth/repository/download/[module]/[revision]/teamcity-ivy.xml' /> <artifact pattern='http://YOUR_TEAMCITY_HOST_NAME/httpAuth/repository/download/[module]/[revision]/[artifact](.[ext])' /> </url> </resolvers> <modules> <module organisation='.*' name='.*' matcher='regexp' resolver='teamcity-rep' /> </modules> </ivyconf>
4. Replace YOUR_TEAMCITY_HOST_NAME with the host name of your TeamCity server.
5. Place ivyconf.xml in the directory where your build.xml will be running.
6. In the same directory create ivy.xml file in which define which artifacts should be downloaded and where to put them, for example:
<ivy-module version="1.3"> <info organisation="YOUR_ORGANIZATION" module="YOUR_MODULE"/> <dependencies> <dependency org="org" name="BUILD_CONFIGURATION_ID" rev="BUILD_REVISION"> <include name="ARTIFACT_FILE_NAME_WITHOUT_EXTENSION" ext="ARTIFACT_FILE_NAME_EXTENSION" matcher="exactOrRegexp"/> </dependency> </dependencies> </ivy-module>
Where
YOUR_ORGANIZATION should be replaced with the name of your organization.
YOUR_MODULE should be replaced with the name of your project or module where artifacts will be used.
BUILD_CONFIGURATION_ID should be replaced with id of the build configuration from where artifacts are downloaded. You can obtain this id from the links in your TeamCity server (you should take value of buildTypeId parameter). e.g. bt20
BUILD_REVISION can be either build number or one of the following strings:
latest.lastFinished
latest.lastSuccessful
latest.lastPinned
ARTIFACT_FILE_NAME_WITHOUT_EXTENSION file name or regular expression of the artifact without extension part.
ARTIFACT_FILE_NAME_EXTENSION extension part of the artifact file name.
7. Modify your build.xml file and add tasks for downloading artifacts, for example (applicable for Ant 1.6 and later):
<target name="fetchArtifacts" description="Retrieves artifacts for TeamCity" xmlns:ivy="antlib:fr.jayasoft.ivy.ant"> <taskdef uri="antlib:fr.jayasoft.ivy.ant" resource="fr/jayasoft/ivy/ant/antlib.xml"> <classpath> <pathelement location="${basedir}/lib/ivy-1.4.1.jar"/> <pathelement location="${basedir}/lib/commons-httpclient-3.0.1.jar"/> <pathelement location="${basedir}/lib/commons-logging.jar"/> <pathelement location="${basedir}/lib/commons-codec-1.3.jar"/> </classpath> </taskdef> <ivy:configure file="${basedir}/ivyconf.xml" /> <ivy:retrieve pattern="${basedir}/tools/ARTIFACT_FILE_NAME_WITHOUT_EXTENSION.ARTIFACT_FILE_NAME_EXTENSION"/> </target>
Please note that among ivy commons-httpclient, commons-logging and commons-codec should be in classpath of Ivy tasks.
Since 2.1 artifacts repository is protected by basic authentication. For accessing artifacts you should provide credentials to the <ivy:configure/> task. For example:
<ivy:configure file="${basedir}/ivyconf.xml" host="YOUR_TEAMCITY_HOST_NAME" realm="TeamCity" username="USER_ID" passwd="PASSWORD"/>
As USER_ID/PASSWORD you can use either username/password of a regular TeamCity user or system properties teamcity.auth.userId/teamcity.auth.password. Second option is preferable since it allows server to track artifacts downloaded by your build. You will see information about downloaded artifacts on the build results page.
See also:
Thanks for your feedback!