How to Create a Custom Access Token in TeamCity


TeamCity provides a UI for creating access tokens with project-specific permissions. However, the UI does not expose every permission available in the TeamCity permission model (based on my experience and setup at least)

I faced this issue when trying to create an access token that could customize build revisions (VCS revisions) in a specific project.

The standard token creation form allows selecting permissions from the Build category, but the Customize build revisions permission is missing from the list, although the user has roles with required rights.

The standard Build permissions include options such as:

  • Change build status
  • Clean build configuration sources
  • Comment build
  • Manually label / merge build sources
  • Mute / unmute problems and tests in project
  • Pause / activate build configuration
  • Pin / unpin build
  • Remove finished build
  • Reorder builds in queue
  • Run build
  • Stop / remove from queue

    As a result, using a token without this permission leads to the following error when attempting to customize a build revision:
HTTP 403 Forbidden
You do not have "Customize build revisions" permission
in project with internal id: project1234

The permission actually exists in TeamCity. The solution is to use the TeamCity REST API to retrieve its ID and explicitly include it when creating a custom access token.

This guide is based on TeamCity 2025.11.8.

Find the TeamCity REST API endpoint

To work around this limitation, we can use the TeamCity REST API.

The endpoint for creating user access tokens is:

POST /app/rest/users/{userLocator}/tokens

For example:

https://TEAMCITY_SERVER/app/rest/users/username:build_user/tokens

You can also inspect the REST API specification available on your TeamCity server:

https://TEAMCITY_SERVER/app/rest/swagger.json

Retrieve all available permissions

Before creating the token, we need to find the internal permission ID.

Use the following request to retrieve permissions assigned to the built-in SYSTEM_ADMIN role:

curl -s \
-H "Authorization: Bearer USER_TOKEN" \
-H "Accept: application/xml" \
"https://TEAMCITY_SERVER/app/rest/roles/id:SYSTEM_ADMIN?fields=permissions(permission(id,name,global))"

The response contains permission IDs, display names, and their scope.

Among the returned permissions, we can find:

<permission id="customize_build_parameters"
name="Customize build parameters"
global="false"/>
<permission id="customize_build_revisions"
name="Customize build revisions"
global="false"/>

This confirms that customize_build_revisions exists in the TeamCity permission model, even though it is missing from the standard Build permissions list in the token creation UI.

The global attribute indicates the permission scope:

  • global="false" — project-level permission.
  • global="true" — global permission.

For our use case, customize_build_revisions is a project-level permission, so we can explicitly associate it with the target project in the token definition.

Create a custom token

Now we can create a token with the required permissions.

Create a file named token.xml:

<token name="myproject-custom-token"
expirationTime="2027-11-27T10:38:59.902+03:00">
<permissionRestrictions>
<permissionRestriction isGlobalScope="false">
<project id="myproject"/>
<permission id="run_build"/>
</permissionRestriction>
<permissionRestriction isGlobalScope="false">
<project id="myproject"/>
<permission id="view_project"/>
</permissionRestriction>
<permissionRestriction isGlobalScope="false">
<project id="myproject"/>
<permission id="view_build_configuration_settings"/>
</permissionRestriction>
<permissionRestriction isGlobalScope="false">
<project id="myproject"/>
<permission id="customize_build_revisions"/>
</permissionRestriction>
</permissionRestrictions>
</token>

The important part is the explicit permission restriction:

<permissionRestriction isGlobalScope="false">
<project id="myproject"/>
<permission id="customize_build_revisions"/>
</permissionRestriction>

Unlike the UI, the XML request allows us to specify the permission ID directly.

Each restriction defines:

  • project — the target TeamCity project ID.
  • permission — the internal permission ID.
  • isGlobalScope="false" — limits the permission to the specified project.

The expiration date uses ISO 8601 format, including the timezone offset.

Send the XML file to TeamCity:

curl -i -X POST \
"https://TEAMCITY_SERVER/app/rest/users/username:build_user/tokens" \
-H "Authorization: Bearer USER_TOKEN" \
-H "Content-Type: application/xml" \
-H "Accept: application/xml" \
--data-binary @token.xml

Replace:

  • TEAMCITY_SERVER with your TeamCity server address.
  • build_user with the target user’s login.
  • USER_TOKEN with an existing token authorized to create tokens for that user.

If the request succeeds, TeamCity creates a new access token with the specified restrictions.

Verify the token permissions

After creating the token, verify that TeamCity saved all restrictions:

curl -s \
-H "Authorization: Bearer USER_TOKEN" \
-H "Accept: application/xml" \
"https://TEAMCITY_SERVER/app/rest/users/username:build_user/tokens?fields=token(name,expirationTime,permissionRestrictions(permissionRestriction(project(id),permission(id),isGlobalScope)))"

Check that the response contains:

<permissionRestriction isGlobalScope="false">
<project id="myproject"/>
<permission id="customize_build_revisions"/>
</permissionRestriction>

Also verify that the token has the expected expiration date and that all permissions are associated with the correct project.

Finally, test the token by attempting to run a build with a custom VCS revision.

Leave a Reply