Integration with Perforce Helix Swarm
Perforce Helix Swarm is a code review tool for Helix Core. When a developer shelves a file and asks for a review, TeamCity can run a build for this change and post the result as a Swarm tests as well as in the comments section of a Helix Swarm review.
Prerequisites
An integration between TeamCity and Helix Swarm is based on the Commit Status Publisher build feature. The Publisher utilizes Swarm tests that solve two tasks:
track whenever a Helix Swarm review is created or edited, and send TeamCity a request to start a new build when this happens;
post statuses of TeamCity builds back to Helix Swarm reviews.
Depending on whether your Helix Swarm setup already has tests that launch TeamCity builds when users create or edit reviews, you can choose one of the two options:
Allow TeamCity to create new Swarm tests. Use this approach when you don't have existing Helix Swarm workflows and tests. This option is available only when you pass admin user credentials to the Commit Status Publisher. If you intend to opt for this option, skip to the Set Up a Commit Status Publisher section as you do not need any additional setup on the Swarm side.
Force TeamCity to find and utilize existing workflows and tests. This approach does not require admin user credentials since TeamCity does not create any Swarm entities. However, you will need to manually set up these entities on the Swarm side.
Helix Swarm Setup
Steps described in this section are performed in Helix Swarm UI, and required only if TeamCity utilizes credentials of a non-admin user to post new Swarm comments.
Create a Test
Helix Swarm Tests can send requests to TeamCity REST API endpoints when a review is created or edited.
![Test in Helix Swarm Test in Helix Swarm](https://resources.jetbrains.com/help/img/teamcity/2023.09/dk-swarm-test.png)
Click Tests in the side navigation pane.
Click the Add Test Definition button.
In a new browser tab, go to TeamCity UI and navigate to Administration | <Your_Build_Configuration>.
Copy the Build Configuration ID value from TeamCity.
Go back to Swarm test settings and paste the copied value as the test name.
In the URL field, enter the following value:
<TeamCity_server_URL>/app/perforce/runBuildForShelveThis value is a TeamCity REST API endpoint that Helix Swarm will use to communicate with your build configuration.
Enter the following string in the Body field:
buildTypeId=<X>&vcsRootId=<Y>&shelvedChangelist={change}&swarmUpdateUrl={update}X
— same value as the test name. Copy from the Build Configuration ID in TeamCity.Y
— in TeamCity, go to Administration | <Your_Build_Configuration> | Version Control Settings | <Your_VCS_Root> and copy the VCS Root ID value.{change}
— the change number.{update}
— the update callback URL.
This string allows Helix Swarm tests to locate a specific TeamCity configuration and schedule a new build for it. For example:
buildTypeId=P4-Remote_MyBuildConfig&vcsRootId=MainP4Root&shelvedChangelist={change}&swarmUpdateUrl={update}To authorize Swarm's requests to TeamCity, click Add header and specify the following values:
Header — "Authorization"
Value — "Bearer ABC", where ABC is a TeamCity user access token.
Set the Timeout setting to 10 seconds.
Click Save to save your new test.
Set Up a Workflow
Helix Swarm Workflows run tests when a users create or edit Swarm reviews.
![Swarm Workflow Settings Swarm Workflow Settings](https://resources.jetbrains.com/help/img/teamcity/2023.09/dk-swarm-workflow.png)
Click Workflows in the side navigation pane.
Create a new workflow or edit the Global Workflow.
In the workflow settings, click Add Test and choose the test you created in the previous step.
Choose the On Update trigger type.
Leave the Blocks value as "Nothing".
Click Save to exit workflow settings.
Set Up a Project
Helix Swarm Project is a group of Helix Core Server users who are working together on a specific codebase.
Click Projects in the side navigation pane.
Create a new project or edit an existing one.
Set the Workflow value to the workflow you created in the previous step. If your test is used in the Global Workflow, choose the "No Workflow" option.
Set Up a Commit Status Publisher
In TeamCity UI, navigate to Administration | <Your_Build_Configuration>.
Switch to the Build Features tab.
Click Add build feature and choose Commit Status Publisher.
Choose Perforce Helix Swarm as a publisher.
Enter the URL of your Helix Swarm instance.
Enter username and ticket. A user whose credentials you specify must have permissions to post comments to Helix Swarm reviews. In addition, make sure that the user's ticket does not expire to prevent the Commit Status Publisher from being unable to access your Swarm instance.
If you do not have any existing workflows and tests that trigger new TeamCity builds, and you want TeamCity to automatically create them when needed, check the Create Swarm Tests option. This setup requires that you pass administrator username and ticket in step 6.
If you already have a workflow that a Commit Status Publisher can use (or you choose to create one to avoid passing administrator credentials to the build feature), leave this checkbox empty.
Click Test Connection to verify the Commit Status Publisher can access your Swarm instance. If you are getting the "Provided credentials lack admin permissions" error, ensure you are not trying to enable the Create Swarm Tests option for non-admin user credentials.
Click Save to add the build feature to your configuration.
Integration Features
After you have set up the Commit Status Publisher, modify and shelve any depot file. Open this shelved change in Helix Swarm and click Request Review. This will trigger a Helix Swarm test that will send TeamCity a request to start a new build. If your integration uses manually configured workflows and tests, a review shows the Tests section that indicates the current test/build status.
![Tests section of a review Tests section of a review](https://resources.jetbrains.com/help/img/teamcity/2023.09/dk-swarm-testInReview.png)
TeamCity attempts to find a user with the same username as a person who requested a review in Helix Swarm, and starts a new personal build for this user. You can click links in the build's Swarm Reviews section to open the shelved change and review in Swarm.
![Personal build in TeamCity Personal build in TeamCity](https://resources.jetbrains.com/help/img/teamcity/2023.09/dk-swarm-personalbuild.png)
You can also view the related change from the build's Changes tab:
![Open Swarm changes from TeamCity Open Swarm changes from TeamCity](https://resources.jetbrains.com/help/img/teamcity/2023.09/dk-swarm-changes-tab.png)
As the TeamCity builds goes through scheduled-started-finished stages, the Commit Status Publisher posts updates in the Comments section of a Helix Swarm review.
![TeamCity comments in Swarm TeamCity comments in Swarm](https://resources.jetbrains.com/help/img/teamcity/2023.09/dk-swarm-comments.png)