Projects need to be built before they can be deployed. Typically, for back-end Java projects, this means generating a .war file. TeamCity builds our projects using Build Configurations that we have configured. These Build Configurations are named the same as the project name and are organized into folders.
When creating a new Build Configuration, use a Template if one is available and applicable to your project. If no applicable Template is available, strongly consider creating a new one since other projects will likely share the same structure as yours. The Template will provide you with a basic setup for your build, but you will have to customize it to fit your specific project.
At the bare minimum, you will have to select your VCS Root (version control system root). Select your project from either Git (new projects) or SVN (legacy projects).
Your template should at least have 1 trigger that triggers off commits to the default branch. Other triggers can be added, such as a trigger that triggers when a dependency of the project finishes building.
Other tabs such as Build Steps, Failure Conditions, Build Features, etc. should likely come from the template and should rarely be customized.
The Java 17 Build template tests a Java 17 project and builds a .war file. Build Configurations for older Java versions do not have a template and were created by copying existing Build Configurations.
The React Build NPM Publish template is used for our “dependency” React projects. It tests and builds the project and publishes the built package to our private NPM repository, Verdaccio. To accomplish this, an NPM Registry Connection is specified in the Build Features.
In addition to running whenever there is a commit to the main branch, it will also run whenever there is a pull request created that targets the main branch. In this case, it will only run tests and will not build or publish. The status of the build will be published to the pull request in GitHub. This requires two Build Features: Pull Requests and Commit Status Publisher.
The React Build For Deploy template is used for our deployed React web applications. It tests and builds the project, producing an artifact that is ready to be deployed to a web server. To pull dependencies from Verdaccio, an NPM Registry Connection is specified in the Build Features.
In addition to running whenever there is a commit to the main branch, it will also run whenever there is a pull request created that targets the main branch. In this case, it will only run tests and will not build or publish. The status of the build will be published to the pull request in GitHub. This requires two Build Features: Pull Requests and Commit Status Publisher.
The Build Configurations in the Deploy project are responsible for deploying our applications to our different environments. Much like our builds, deployment configurations should use an existing template if possible.
The Maven War Deploy – Non-Prod template handles deployments of our Java applications to our non-production Tomcat servers.
The template is built using the device-management project, so some changes need to be made to any new deployment created from this template.
1. Under the Triggers tab, Edit the Finish Build Trigger and replace the device-management build configuration with your own project’s build configuration. Make sure the Branch Filter has the correct default branch name, depending on the version control system.
2. Under the Dependencies tab, Edit the Artifact Source and replace the device-management build configuration with your own project’s build configuration.
3. Under the Parameters tab, override the applicationName parameter with the name of your application. Also override the devServer and testServer if needed.
When selecting Deploy, you will be prompted to select an Environment to deploy to (dev or test). There is also a checkbox labeled Restart Only which, if checked, will just restart the application that is currently deployed to that environment instead of deploying a new .war file.
The Maven War Deploy – Prod template handles deployments of our Java applications to our production Tomcat servers.
The template is built using the device-management project, so some changes need to be made to any new deployment created from this template.
1. Under the Triggers tab, Edit the Finish Build Trigger and replace the device-management build configuration with your own project’s build configuration. Make sure the Branch Filter has the correct default branch name, depending on the version control system.
2. Under the Dependencies tab, Edit the Artifact Source and replace the device-management build configuration with your own project’s build configuration.
3. Under the Parameters tab, override the applicationName parameter with the name of your application. Also override the prodServer if needed.
When selecting Deploy, you see the prod environment selected. There is also a checkbox labeled Restart Only which, if checked, will just restart the application that is currently deployed to that environment instead of deploying a new .war file.
After confirming the deployment, it will need 2 approvals from the Prod Deploy Approvers group for it to start. If the user that creates the deployment is in the Prod Deploy Approvers group, they will automatically count as 1 of the approvers.
The React Web Deploy – Non-Prod template handles deployments of our React applications to our non-production web servers.
The template is built using the customer-portal project, so some changes need to be made to any new deployment created from this template.
1. Under the Triggers tab, Edit the Finish Build Trigger and replace the customer-portal build configuration with your own project’s build configuration.
2. Under the Dependencies tab, Edit the Artifact Source and replace the customer-portal build configuration with your own project’s build configuration.
3. Under the Parameters tab, override the applicationPath parameter with the path to your application on the server. Also override the devServer and testServer if needed.
When selecting Deploy, you will be prompted to select an Environment to deploy to (dev or test).
The React Web Deploy – Prod template handles deployments of our React applications to our production web servers.
The template is built using the customer-portal project, so some changes need to be made to any new deployment created from this template.
1. Under the Triggers tab, Edit the Finish Build Trigger and replace the customer-portal build configuration with your own project’s build configuration.
2. Under the Dependencies tab, Edit the Artifact Source and replace the customer-portal build configuration with your own project’s build configuration.
3. Under the Parameters tab, override the applicationPath parameter with the path to your application on the server. Also override the prodServer if needed.
When selecting Deploy, you see the prod environment selected.
After confirming the deployment, it will need 2 approvals from the Prod Deploy Approvers group for it to start. If the user that creates the deployment is in the Prod Deploy Approvers group, they will automatically count as 1 of the approvers.