Artifact Dependencies
Configuring Artifact Dependencies Using Web UI
To add dependencies to a build configuration:
When Creating and Editing Build Configurations, open Dependencies page.
Click the Add new artifact dependency link and specify the following settings:
Option
Description
Depend on
Specify the build configuration that the current build configuration should depend on.
Get artifacts from
Specify the type of build, from which the artifacts should be taken: last successful build, last pinned build, last finished build or build with specific build number.
Build number
Use this field to specify the exact Configuring General Settings of the artifact. This field is enabled, if the Build number option is selected in the Get artifacts from field.
Specifies the files to be downloaded form the "source" build. The path should be relative to the artifacts directory of the "source" build. The path can either identify a specific file, or use wildcards to match multiple files. Wildcards are supported. Downloaded artifacts will keep the "source" directory structure starting with the first
*or?.For example:
Use to download all files from a/b directory of the source build. If there is a file in the source build artifacts, it will be downloaded into the file
DestinationPath /c/file.txt.At the same time, artifact dependency
**/*.txtwill preserve the directories structure: the file from source build artifacts will be downloaded toDestinationPath /a/b/c/file.txt.
Artifacts can also be extracted from zip/jar/tar/tar.gz archives, using special
'!'syntax:<path to sourcefile.zip>!<Ant-like-wildcard>The files matched inside the archive will be placed in the directory corresponding to the first directory with a wildcard in the name. For example:
release.zip!*.dllcommand will extract all .dll files residing in the root ofrelease.zipartifact.Examples of advanced usage:
release-*.zip!*.dllwill extract *.dll from all archives matchedrelease-*.zippattern.a.zip!**will unpack entire archive saving path information.a.zip!a/b/c/**/*.dllwill extract all .dll files froma/b/cand its subdirectories, into the destination directory, withouta/b/cprefix.
More artifacts
Click this link to open an additional text field, where you can specify the path to additional artifacts.
Destination path
Specify the destination path on the agent where downloaded artifacts should be placed. If the path is relative, it will be resolved against the Build Checkout Directory. If needed, the destination path can be cleaned before downloading artifacts.
Clean directory before downloading artifacts
Check this option to delete the content of the destination directory before copying artifacts.
xml Configuring Artifact Dependencies Using Ant Build Script
This section describes how to download TeamCity build artifacts inside the build script. These instructions can also be used to download artifacts from outside of TeamCity.
For handling artifact dependencies between the builds this solution is more complicated then configuring dependencies in the TeamCity UI but allows for greater flexibility. For example, managing dependencies this way will allow you to start a personal build and verify that your build is still compatible with dependencies.
To configure dependencies via Ant build script: 1. Download 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:
<ivysettings> <property name='ivy.checksums' value=''/> <caches defaultCache="${teamcity.build.tempDir}/.ivy/cache"/> <statuses> <status name='integration' integration='true'/> </statuses> <resolvers> <url name='teamcity-rep' alwaysCheckExactRevision='yes' checkmodified='true'> <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> </ivysettings>
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_ORGANIZATIONshould be replaced with the name of your organization.YOUR_MODULE shouldbe replaced with the name of your project or module where artifacts will be used.BUILD_CONFIGURATION_IDshould 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. bt20BUILD_REVISIONcan be either build number or one of the following strings:latest.lastFinishedlatest.lastSuccessfullatest.lastPinned
ARTIFACT_FILE_NAME_WITHOUT_EXTENSIONfile name or regular expression of the artifact without extension part.ARTIFACT_FILE_NAME_EXTENSIONextension 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-2.0.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}/[artifact].[ext]"/> </target>
Artifacts repository is protected by a basic authentication. To access the artifacts, you need to provide credentials to the <ivy:configure/> task. For example:
<ivy:configure file="${basedir}/ivyconf.xml" host="TEAMCITY_HOST" realm="TeamCity" username="USER_ID" passwd="PASSWORD"/>
where TEAMCITY_HOST is hostname or IP address of your TeamCity server (without port and servlet context). As USER_ID/PASSWORD you can use either username/password of a regular TeamCity user (the user should have corresponding permissions to access artifacts of the source build configuration) or system properties teamcity.auth.userId/teamcity.auth.password.
The properties teamcity.auth.userId/teamcity.auth.password store automatically generated build-unique values whose only intended use is artifacts downloading within the build script. The values are valid only during the time the build is running. Using the properties is preferable to using real user credentials since it allows the server to track artifacts downloaded by your build. If the artifacts were downloaded by the build configuration artifact dependencies or using the supplied properties, the specific artifacts used by the build will be displayed on the Dependencies tab. In addition, the builds which were used to get the artifacts from will not be cleaned up by the Clean-Up process much like the pinned builds.