Team City: Using exported build parameters in dependent build configurations

What I learned today — 26 February 2018

Niel de Wet
1 min readFeb 27, 2018

Yesterday I described how to interact with the Team City build server by logging specially formatted service messages. The example was setting build parameters. These can then be used in build configurations (or steps) that depend on the one which set the parameter.

In this post I’ll show how to use this feature in a build pipeline that builds a Docker image (call this build configuration Build Image) and then deploys it (call this build configuration Deploy Container).

1. Build Image

Build, tag and push the Docker image. Then export the image name and tag as a parameter.

TAG=v1
docker build -f Dockerfile --tag reg.example.com/example/coolapp:${TAG}
docker push reg.example.com/example/coolapp:v1
echo "##teamcity[setParameter name='BuiltImage' value='coolapp:${TAG}']"

2. Deploy Container

First configure Deploy Container to have a snapshot dependency on Build Image. Now the parameters of Deploy Container, including BuiltImage, can be accessed by Deploy Container, the dependent build. Dependency properties have the format:

dep.<Dependency build ID>.<Property name>

Let’s see how this can be used. For simplicity we’ll assume that the Docker client is connecting to the Docker Daemon on the target host.

docker run -d reg.example.com/example/%dep.BuildImageID.BuiltImage%

Conclusion

Exporting parameters and referencing those in dependent build configurations is a great way of passing data between steps in a build pipeline.

--

--

Responses (1)