Creating TeamCity Projects

Short module on how to pull repositories from different sources

Module Objectives

  • Pulling Public Repositories from GitHub

  • Pulling Private Repositories from GitLab

Introduction

TeamCity's projects consist of repositories pulled from public and private sources such as an internal GitLab server, or GitHub. By default, TeamCity will check for updates from the repository every 60 seconds, then pull the latest changes - though this can be changed per project if this is not something that you want/need.

You can also select which branches to pull from - either the default main branch, all branches (by inserting a wildcard *), or a specific branch such as dev or nightly if you're looking for bleeding edge changes.

Public Repositories

Creating your public project

To create our project, first get a GitHub link (We will use Seatbelt and Ligolo-ng for our demo). On TeamCity, select Create Project -> From a repository URL -> <REPOSITORY LINK> -> Proceed

Create Project -> Seatbelt
  • Make sure you have an internet connection to your server

  • Add a username and token if you are pulling from a private repository

Next, change the builder configuration name to something memorable or related to the project, and add the branch that you would like to monitor. You can go to the original project's repository to see what the other branches are. Once you're ready, click proceed.

TeamCity Project Setup
Seatbelt GitHub Repository

After clicking proceed, you will be met with the configuration page for our builder. TeamCity will automatically detect a build step to use based on our project, but we can change this later

TeamCity build step detection

Use the selected build step, then click on edit next to the .NET builder

Editing the build step

The compile instructions on Seatbelt tells us to use .NET 3.5 or 4.0 to build our project, and to target release. We will reflect these requirements in our build step.

Seatbelt Compile Instructions
  1. Set the MSBuild Version to 2019

  2. Set the Required SDK to 3.5 or 4.0

  3. Set the Configuration to Release

  4. Save your changes

.NET build step

Now, we need to specify where our binary will be built. We will choose Seatbelt\bin\Release\Seatbelt.exe

Artifact Path

Troubleshooting

Install Agent
Agent Download URL

Cont.

If everything went well, you should be able to run your build step, and get your first artifact!

Running the build step

If the build is successful, you should see the Seatbelt executable in your artifacts tab, if you cannot find it here then add the C:\BuildAgent directory to your Defender exclusions (if you've installed an agent post server setup)

Successful Build
Seatbelt Executing Successfully

You can download the artifact by clicking on its name. You might need to add another exclusion at C:\ProgramData\JetBrains\TeamCity. We will take a look at how to make the binary less detectable in the next chapter.

Defender nuking our artifact

Private Repositories

Pulling from private repositories is just as easy as from public ones, the only difference is that private repositories must be accessible and you must have the necessary credentials to access them.

If you recall from the previous module, we added our SSH key and created an access token. We will use these to pull the repository - the same can be done for GitHub using Personal Access Tokens or SSH keys.

Let's try pulling our calculator project, then testing and building it using TeamCity

# Double check your connection to your GitLab server from TeamCity's server
PS> ping 192.168.8.142

Pinging 192.168.8.142 with 32 bytes of data:
Reply from 192.168.8.142: bytes=32 time<1ms TTL=64
Reply from 192.168.8.142: bytes=32 time<1ms TTL=64
Add your credentials and the repo

If successful, you should see this screen:

Successful authentication

Go to the next section, then click on Build Features - we have to enable the Golang feature to be able to run Go commands

Golang build feature

Go back to Build Steps, then in the Command Line option paste this in:

go test -json ./...
exit 0

This will run a test on all the folders within the project.

Command Line options

Save and run this step. If the build succeeds, you should see a tab called Tests and the two test cases that we have set in Simple Calculator Project

Tests succeeded

You can add a second build step after the test with go build ./... -o calculator to get your executable

Last updated

Was this helpful?