Quantcast
Channel: TeamCity : Powerful CI/CD for DevOps-centric teams | The JetBrains Blog
Viewing all articles
Browse latest Browse all 916

How to Use the Space Git Flow With TeamCity

$
0
0
JetBrains Space Git flow with TeamCity

Do you use feature branches or Git flow to ensure code quality?

The powerful combination of JetBrains Space Git flow with TeamCity offers a complete solution to help you achieve better code quality and keep your main branch green with stable builds. 

Space provides you with Git hosting, code reviews, and quality gates, while TeamCity offers a build pipeline. The native integration between tools will save you time and effort by ensuring you have a complete and well-integrated flow with a unified UI. 

Adopting the Space Git flow with TeamCity is easy and allows you to keep your main branch stable while controlling changes automatically. 

In this blog post, we’ll introduce the combo of the Space Git flow and TeamCity, and guide you through the process of using it in your project.

Get started with Space for free

What Is the Space Git Flow, and Why Use it?

The Space Git flow is a branching strategy that is similar to GitHub flow, but with a greater emphasis on safety when introducing changes to the main branch and the ability to scale to large projects and teams.

JetBrains Space Git flow with TeamCity

Getting started with the Space Git flow is easy and doesn’t require going all-in, as you can mirror your existing Git repository without having to migrate, and you can switch back any time.

Using the Space Git flow integrated with TeamCity allows you to:

  • Achieve higher-quality code and a stable main branch by configuring quality gates based on TeamCity build status for merge requests.
  • Introduce a code review process your team will love, integrated with IntelliJ IDEA and available on the go with Space iOS and Android apps.

Read this article to learn more about the Space Git flow.

How to Use the Space Git Flow With TeamCity

Watch this 3-minute video to see how the combination of the Space Git flow and TeamCity works in a project:

Read on to learn about the flow in more detail.

Mirror or host your Git repository in Space

Start by creating bi-directional mirrors of your repository from GitHub or another Git service and link it to Space in a few clicks. 

You can also use Space to host your source code privately. If you host it in Space, you can take advantage of the web-based interface and JetBrains IDE integration for a seamless development experience.

Protect your main branch from accidental pushes  

To prevent accidental pushes to the main branch, you can set up branch protection in Space. This helps you protect repositories from unauthenticated commits, restrict who can push or merge changes into the branch, and prevent accidental branch deletion.

Branch protection in Space

Once you’ve set up branch protection, the only way a change can make it to main is through a merge request.

Create a feature branch

To start working on a new feature, you’ll need to either clone the repository to your machine, or use remote development with the IDE hosted on a virtual machine in the Space cloud.

Clone your repository

With the Space Git flow, you make changes in a separate feature branch and then request a code review before merging it back to main. From your IDE, you can make changes, add a commit message, and then push this branch back to Space. 

Push commits to Space

Create a merge request

Create a merge request to begin the process of moving your new code into main. You can do this from within your IDE using the native integration, or you can find your branch in Space and create a merge request from there.

Create a merge request

You can create a title and description for your merge request and see the commits that will be part of it. The quality gates configured in Space require at least one person to review these changes.

Merge request in Space

Quality gates are a mandatory and customizable set of conditions that need to be fulfilled before merging. Apart from code reviewer’s approval, you can set up a Space Automation job and a TeamCity check as gates.

Space will require a review based on code ownership

In your repository, you can create a special file named CODEOWNERS that specifies who is responsible for specific folders and files. Later, you and your colleagues will have the option to select a code owner to review your changes as a part of quality gates.

Wait for your team to review the changes 

Now you wait for your colleagues to review the changes. They can add comments and suggestions, or they can simply approve the request. With turn-based code reviews, Space makes it easy for both the author and the reviewer to understand whose turn it is to take action.

Review code in Space

Space allows you to collect your comments as drafts and send them in batches so as not to overload your colleagues with unnecessary notifications.  

After you’ve agreed on changes with your reviewer, you can proceed with merging them.

Ensure your build is green 

With Space and TeamCity, there are a few options that you can use to make sure your build is green before merging your changes. You can use either or both of them for extra security.

Run CI/CD checks

After you create a merge request, Space Automation and/or TeamCity CI jobs are triggered to validate the changes by building the code and running tests. As part of quality gates, the changes will be merged into main only if a CI/CD server can successfully build the feature branch. 

The checks can be set and completed by both Space Automation and TeamCity.

Quality gates in Space

These checks, however, only ensure the new code is valid and integrates well with the main branch at the time of branching. With Safe Merge, validation is done by attempting to integrate the new code with the very latest code from the main branch.

Run Safe Merge 

You can use Safe Merge before merging the changes directly into main. Safe Merge acts like a time machine – it runs a preview of what your main branch would look like with the changes. 

This can be especially useful for large projects because while you were working on a feature branch, the main branch could have received changes that conflict with your work. Safe Merge allows you to catch these conflicts before actually merging the branches.

Space creates a temporary commit with the latest changes, which can then be used to perform the required quality checks using an Automation job or TeamCity build.

In TeamCity, you’ll see Space trigger a special build, and TeamCity will report the build status back to Space when it’s finished. The changes are merged into the main branch only if the build succeeds. Otherwise, the merge is rejected.

TeamCity build

Using the Space Git flow together with TeamCity ensures that changes to your code base are always reviewed. And thanks to Safe Merge, you’ll always have a main branch that compiles and can be deployed successfully.

How to Get Started With the Space Git Flow and TeamCity

If you already use TeamCity, getting started with the Space Git flow is easy. 

Get started with Space for free

What do you think about the combination of the Space Git flow and TeamCity? We’d love your feedback in the comments below.


Viewing all articles
Browse latest Browse all 916

Trending Articles