PHASE 10 OF 15

Build Features

Add-on behaviours that enhance build configurations without modifying build steps — all 15+ features in TeamCity 2017.2.2 with setup instructions and gotchas

Commit StatusPR SupportCoverageDockerSSH Agent
1

Build Features Overview

Build features are optional add-ons configured under Build Configuration → Build Features → Add build feature. Multiple features can be active simultaneously. They are applied around the build steps without modifying them.

Commit Status Publisher
Post ✓/✗ to GitHub, Bitbucket, GitLab, Upsource after each build
Pull Requests
Auto-detect and enrich GitHub/Bitbucket PR builds with PR metadata
Code Coverage (JaCoCo)
Java coverage — line, branch, method. Shows coverage report in build
Code Coverage (dotCover)
.NET coverage using JetBrains dotCover
Duplicates Finder (Java)
Detect duplicate code blocks; configurable threshold
Inspections (Java)
Run IntelliJ IDEA inspections; Checkstyle, PMD, FindBugs support
File Content Replacer
Token substitution in files before build (version injection)
SSH Agent
Forward SSH key to build steps for SSH-based deployments
Docker Support
docker login before build; docker logout + cleanup after
Swabra
Clean up files created by build but not in VCS after build ends
Performance Monitor
Collect CPU/RAM/disk metrics on agent during build
Shared Resources
Semaphore/lock for exclusive access to shared resources (DB, port)
Build Files Cleaner
Delete specific files/dirs after build (e.g., test fixtures)
Notifications
Per-build-config notification rules on top of user notification settings
2

Commit Status Publisher

Already covered in Phase 5. Quick reference for configuration:

PublisherURLAuthToken scopes
GitHub.comhttps://api.github.comPAT or connectionrepo:status
GitHub Enterprisehttps://ghe.company.com/api/v3PATrepo:status
Bitbucket Cloudhttps://api.bitbucket.orgUsername + app passwordRepositories: write
GitLabhttps://gitlab.com/api/v4Personal access tokenapi
3

Pull Request Support

Covered in Phase 5. Additional configuration option not covered there:

Filter by target branch

Only build PRs targeting a specific branch. Enter branch patterns:

# Only build PRs targeting main or develop
refs/heads/main
refs/heads/develop

# Build PRs targeting any release branch
refs/heads/release/*
Filter by author role

Options: All (including forks), Members (org members only), Members and external contributors with write access. For public repos, use Members to prevent fork-based CI abuse.

4

Code Coverage: JaCoCo (Java)

JaCoCo integration instruments Java bytecode and reports line, branch, and method coverage. The coverage report appears in the build's Code Coverage tab and on the build overview as a percentage bar.

Maven setup

TeamCity injects JaCoCo agent into the JVM automatically when the JaCoCo build feature is enabled — no changes to your pom.xml required for basic coverage.

  1. Add build feature: Code Coverage → JaCoCo.
  2. Instrumentation classes: ** (all classes). Narrow to your source packages for accurate results: com/yourcompany/**.
  3. Exclude: test classes, generated code: **/*Test*, **/*Generated*.
  4. Coverage threshold (optional): fail build if line coverage drops below 80%.
GOTCHA — JaCoCo and multi-module Maven

For multi-module Maven projects, JaCoCo must aggregate coverage across modules. Use the jacoco:report-aggregate goal in a parent pom, or configure TeamCity to look for coverage files in all modules: **/jacoco.exec. Without aggregation, coverage is only reported for the last module that ran tests.

5

Duplicates Finder (Java)

Scans Java source files for duplicated code blocks. Reports are shown in the Duplicates tab of the build.

SettingRecommended value
Minimum token count150 (short duplicates are often acceptable patterns)
Source pathssrc/main/java (exclude test sources)
ExcludeGenerated sources: target/generated-sources/**
Fail on new duplicatesOptional — only fail if count INCREASES vs previous build
6

Inspections (IntelliJ IDEA)

Runs IntelliJ IDEA's code inspections on the source — Checkstyle, PMD, FindBugs/SpotBugs, and IDEA's own inspections (unused imports, null pointer risks, etc.).

GOTCHA — IntelliJ IDEA must be on agent

The Inspections build feature requires a full IntelliJ IDEA installation on the build agent — not just the JDK. IntelliJ is typically not installed on CI servers. This feature is mainly useful if you have a dedicated agent with IntelliJ installed. Most teams use Maven Checkstyle/PMD plugins instead, which run without IntelliJ.

Alternative: Maven Checkstyle step
# Instead of IntelliJ inspections, use Maven Checkstyle runner:
# Build step: Maven runner
# Goals: checkstyle:check
# Fails build if violations exceed configured threshold

# Or inline in pom.xml:
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-checkstyle-plugin</artifactId>
  <configuration>
    <failsOnError>true</failsOnError>
  </configuration>
</plugin>
7

File Content Replacer

Replaces tokens in files before build steps run. Ideal for injecting the build number into version files, configuration files, or assembly info files. The replacement is applied on the agent's working copy — the original files in VCS are not modified.

Example: inject build number into version.properties
# File Content Replacer configuration:
File pattern:       src/main/resources/version.properties
Find what:          APP_VERSION=SNAPSHOT
Replace with:       APP_VERSION=%build.number%
Regular expression: No (literal text replacement)
Example: .NET AssemblyInfo.cs version injection
File pattern:       **/AssemblyInfo.cs
Find what:          \[assembly: AssemblyVersion\(".*"\)\]
Replace with:       [assembly: AssemblyVersion("%build.number%.0")]
Regular expression: Yes
REPLACEMENT ORDER

File Content Replacer runs before all build steps. This means the modified file is in place when Maven/Gradle/MSBuild runs. The replacement is applied to the working copy only — it does not affect VCS or committed code.

8

SSH Agent

The SSH Agent build feature starts an ssh-agent process on the agent and loads a specified key. Build steps can then make SSH connections (git push, rsync, ssh deploy) using that key without specifying credentials explicitly.

  1. Upload a private key in Administration → <Project> → SSH Keys.
  2. Add build feature: SSH Agent.
  3. Select the uploaded key.
  4. Build steps now have access to the key via the ssh-agent socket ($SSH_AUTH_SOCK).
# In a Command Line deploy step:
# No need to specify -i /path/to/key — ssh-agent handles it
rsync -avz --delete dist/ deploy@prod-server:/var/www/app/
ssh deploy@prod-server "systemctl restart app"
GOTCHA — SSH Agent vs SSH Exec runner

The SSH Agent build feature loads a key into ssh-agent so your own scripts can use it. The SSH Exec build step runner (Phase 4) is a different thing — it directly executes a command on a remote host over SSH. They can be used together: SSH Agent provides the key, SSH Exec runner uses it for deployment.

9

Docker Support

The Docker Support build feature handles Docker registry login/logout and optionally cleans up Docker images created during the build.

Setup
  1. Add build feature: Docker Support.
  2. Add a Docker registry: select from project connections or enter registry URL + credentials.
  3. Enable Clean up pushed images (optional): TeamCity tracks images pushed during the build and removes them after the build completes. Prevents unbounded registry growth.
# With Docker Support feature active, build steps can use docker commands
# without logging in explicitly:

# Build step: Command Line
docker build -t registry.yourcompany.com/myapp:%build.number% .
docker push registry.yourcompany.com/myapp:%build.number%

# The Docker Support feature:
# 1. Runs docker login BEFORE steps (using stored credentials)
# 2. Runs docker logout AFTER steps
# 3. If cleanup enabled: removes the pushed image tag after build
10

Swabra — Agent Cleanup

Swabra detects files created during the build that are not part of the VCS checkout and removes them after the build. Prevents build pollution — if build A creates a temp file, build B (on the same agent) won't accidentally pick it up.

SettingDescription
Clean checkout if cannot restore clean directoryForces full clean checkout if Swabra can't restore the clean state. Safer but slower.
Lock files for writing during buildTracks which files are modified; removes extra files after build ends
Strict cleanupRemoves ANY file not in VCS — useful when builds generate files that must not leak between runs
11

Performance Monitor

Collects CPU, memory, and disk I/O metrics on the agent during the build. Results appear in the build's Build Statistics charts. Useful for diagnosing builds that are getting slower over time.

No configuration required — just add the build feature and data is collected automatically at 3-second intervals during the build.

12

Shared Resources

Shared Resources implement semaphore-style locking to prevent concurrent access to limited resources — a test database, a hardware device, a specific port on an agent, or an external API with rate limits.

Setup
  1. Define the resource: Administration → <Project> → Shared Resources → Add resource. Name it (e.g., integration-test-db). Set a quota (max concurrent users: 1 for exclusive access).
  2. Add build feature: Shared Resources to each build config that needs the resource.
  3. Select the resource and lock type: Writeable lock (exclusive) or Readable lock (shared, up to quota).

When a build needs the resource, TeamCity waits in the queue until the resource is available. Only then is the build assigned to an agent.

Up Next — Phase 11: Templates & Meta-Runners

Stop copying build configurations — create templates that propagate to all configs at once, and package custom runners as meta-runners for reuse across projects.

Continue to Phase 11 → Back to Hub