TeamCity
How to integrate TeamCity with Cloudsmith

Integrating TeamCity with Cloudsmith enables seamless management of your software packages within your CI/CD pipelines. This integration allows you to push build artifacts directly to Cloudsmith repositories from TeamCity, leveraging TeamCity’s build pipelines for efficient artifact publishing.
The Cloudsmith CLI gives you full control when connecting to any CI/CD process; allowing you to upload any of our support formats or query your repositories. Just configure your API Key, install the CLI, and you'll be all set.
Prerequisites
Before proceeding, ensure you have the following:
- TeamCity Server: A functioning installation of TeamCity.
- Cloudsmith Account: An active Cloudsmith account with the necessary repository access.
- API Key: A Cloudsmith API key for authentication, obtainable from your Cloudsmith account under Account > API Settings.
- Build Agent: A configured build agent to execute TeamCity builds.
Integration Steps
Go to Project Build Configuration in TeamCity and add the following build steps:
Step 1: Install Python
- Runner Type: Command Line
- Custom Script:
apt-get update -y apt-get install -y python3 python3-pip
- Execution Policy: If all previous steps finished successfully.
You can skip this step if the build agent is consistent as Python installation is a one-time setup
Step 2: Install Cloudsmith CLI
- Runner Type: Command Line
- Custom Script:
pip install cloudsmith-cli
- Execution Policy: If all previous steps finished successfully.
Step 3: Add Cloudsmith API Key Parameter
- Navigate to Project Settings > Parameters.
- Add the following parameter:
- Name: env.CLOUDSMITH_API_KEY
- Kind: Environment variable(env.)
- Value Type: Password (to ensure security).
- Value: Your Cloudsmith API key.

Step 4: Push Your Artifacts
- Runner Type: Command Line
- Custom Script:
cloudsmith push raw <owner>/<your-repository> <artifact-path>
- Replace / and with:
- Replace with your Cloudsmith Organisation name.
- Your Cloudsmith Repository Name: For example, my-repository.
- Artifact Path: Artifact path, such as ./example-artifact.tar.gz.
- Execution Policy: If all previous steps finished successfully.
Enable Versioned Settings in TeamCity
Optional: If you want to track build configuration in your VCS.
- In Project Settings, navigate to Versioned Settings.
- Configure the following options:
- Synchronization: Enable.
- Project settings VCS root: Set as per your preference.
- Settings format: Choose either from Kotlin or XML.
- Settings path in VCS: .teamcity
- Allow editing project settings via UI: Enable.
- Store passwords and API tokens outside of VCS: Enable.
- Apply the changes to ensure your build configuration is tracked in the version control system (VCS).
- Allow it to complete and then hit Commit current project settings button and TeamCity will commit the build configuration to your VCS.

Here's a Kotlin Snip for You Reference
import jetbrains.buildServer.configs.kotlin.*
import jetbrains.buildServer.configs.kotlin.buildFeatures.perfmon
import jetbrains.buildServer.configs.kotlin.buildSteps.script
import jetbrains.buildServer.configs.kotlin.triggers.vcs
version = "2024.03"
project {
buildType(TestCloudsmith)
}
object TestCloudsmith : BuildType({
name = "TestCloudsmith"
artifactRules = "./"
params {
password("env.CLOUDSMITH_API_KEY", "credentialsJSON:4ad9ee86-2dd4-4acf-8070-123e96c647fc")
}
vcs {
root(DslContext.settingsRoot)
}
steps {
script {
name = "InstallPython"
id = "InstallCloudsmith"
scriptContent = """
apt-get update -y
apt-get install -y python3 python3-pip
""".trimIndent()
}
script {
name = "InstallCloudsmith"
id = "InstallCloudsmith"
scriptContent = "pip3 install cloudsmith-cli"
}
script {
name = "CheckCloudsmithAuth"
id = "CheckCloudsmithAuth"
scriptContent = "cloudsmith whoami"
}
script {
name = "Cloudsmith Push"
id = "Cloudsmith_Push"
scriptContent = "cloudsmith push raw testenv/rawrepo raw-example.tar.gz"
}
}
triggers {
vcs {
}
}
features {
perfmon {
}
}
})
Best Practices
- Use Entitlement token Authentication: If you only need to pull packages, use Entitlement tokens for authentication to avoid using long-lived API keys.
- Secure Secrets: Store sensitive information like API keys/Entitlement tokens as Passwords instead of any other Value type.
Troubleshooting
- Authentication Issues: Verify the API key is correctly configured as a hidden parameter.
- Artifact Upload Errors: Ensure owner/your-repository and artifact-path are properly specified in the push command.
- Build Failures: Review the TeamCity build logs for errors in specific steps.
Updated 3 days ago