Skip to content

TeamCity

CodeCharter in a TeamCity build step.

TeamCity build step (Command Line):

#!/bin/bash
set -e

# Download
curl -sSL -H "Authorization: Bearer %env.CODECHARTER_API_KEY%" \
    -o codecharter.tar.gz \
    https://codecharter.tools/api/v1/cli/linux-x64/1.4.0
mkdir -p codecharter-bin && tar -xzf codecharter.tar.gz -C codecharter-bin
chmod +x codecharter-bin/codecharter

# Analyze with TeamCity Service Messages
codecharter-bin/codecharter analyze . \
    --fail-on error \
    --output console \
    2>&1 | tee codecharter.log

# Optionally publish as artifact
echo "##teamcity[publishArtifacts 'codecharter.log']"

API key

In TeamCity: Project → Parameters → Environment variable CODECHARTER_API_KEY, type "Password". Store it at project level so all build configurations can access it.

Caching

// .teamcity/CodeCharter.kt (Kotlin DSL)

steps {
    script {
        name = "Restore cache"
        scriptContent = """
            mkdir -p ~/.cache/codecharter
            # TeamCity Build Cache Plugin or similar
        """.trimIndent()
    }
}

Using TeamCity's built-in build caches you can persist ~/.cache/codecharter between builds.

Self-hosted agents

Works without any changes. The agent needs internet access to codecharter.tools, or you can mirror the binary into a local artifact repository.