Build and test a Golang app with Gitness
Tags: devops, go, tutorial, gitness
Published: 2023-10-20 19:33:22


[Gitness](https://gitness.com?utm_source=dev.to&utm_content=blog&utm_medium=blog&utm_term=gitness-build-and-test-golang-app) is an open source development platform from [Harness](https://www.harness.io?utm_source=dev.to&utm_content=blog&utm_medium=blog&utm_term=gitness-build-and-test-golang-app) that hosts your source code repositories and runs your development life cycle pipelines.

This tutorial covers how to build and test a Golang application with Gitness.

## Installation

You can [install](https://docs.gitness.com/#installation) Gitness on any computer running [Docker](https://www.docker.com).

Run this command to start Gitness:

```
docker run -d \
  -p 3000:3000 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v /tmp/gitness:/data \
  --name gitness \
  --restart always \
  harness/gitness
```

Visit [http://localhost:3000](http://localhost:3000) in your browser and you will be greeted with the Gitness login page.

Click the __Sign Up__ link.

| ![Gitness login page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5tzsdclld76ymj1nu764.png) |
|-|

Enter your desired user ID, email address and password, then click __Sign Up__.

| ![Gitness sign up page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ree9uxd0ztlk4sl1bhsw.png) |
|-|

| ℹ️ Note |
|---------|
| __By default, the first user to sign up will be granted administrator access.__ To learn more about how to configure Gitness, refer to the [configuration](https://docs.gitness.com/administration/configuration) documentation. |

## Create Project

Create a [project](https://docs.gitness.com/administration/project-management) which will contain the Git repository.

Click the __New Project__ button.

| ![Gitness new project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/14tavsu9odimyy49ij05.png) |
|-|

Give the project a name and optional description, then click the __Create Project__ button.

| ![Gitness create project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lgqy9u3cz4l094pvrp5y.png) |
|-|

## Import Repository

Expand the __New Repository__ drop-down menu and select __Import Repository__.

| ![Gitness new repository](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qs4acmsbgc6edzx67xsz.png) |
|-|

[jimsheldon/go-outyet](https://github.com/jimsheldon/go-outyet), is a simple Golang application that reports whether a version of Golang has been released yet.

Enter `https://github.com/jimsheldon/go-outyet` in the __Repository URL__ field, then click __Import Repository__.

| ![Gitness import repository](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rpz8ox5xqkstakuft1h3.png) |
|-|

## Create Pipeline

Click on the imported repository, then open the __Pipelines__ view from the menu on the left.

| ![Gitness open pipelines](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bhnowaadm6tphyz1kqn7.png) |
|-|

Click the __New Pipeline__ button.

| ![Gitness new pipeline](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/euni8g3z3ljifmfi8mis.png) |
|-|

Give the pipeline a name, the YAML path will be generated automatically (it can be changed if desired), then click the __Create__ button.

| ![Gitness create new pipeline](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cljz75dpba9eyyabwege.png) |
|-|

Gitness can automatically generate a pipeline based on the code in the repository.

Click the __Generate__ button above the pipeline editor.

| ![Gitness generate pipeline](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/algy949s174ybkwa4qpl.png) |
|-|

Examine the pipeline that was generated, you will see [run steps](https://docs.gitness.com/pipelines/steps/run) that build and test the app, and a Docker build [plugin step](https://docs.gitness.com/pipelines/steps/plugin).

The build step compiles the binary, and the test step runs unit tests from the `main_test.go` file.

The Docker build step builds a Docker image from the `Dockerfile` file, but does not publish the image (the `dry_run: true` setting prevents publishing).

Click __Save and Run__ button.

| ![Gitness save and run pipeline](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tjo47sgyczymidxjmdgf.png) |
|-|

| ℹ️ Note |
|---------|
| Gitness will commit the pipeline file to your repository and create a default pipeline [trigger](https://docs.gitness.com/pipelines/triggers) for pull request events, which can be customized if desired. |

## Run Pipeline

Click the __Run pipeline__ button in the window that appears.

| ![Gitness run pipeline](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c5k7mvfofyssinjad022.png) |
|-|

You will see the pipeline execution view.

| ![Gitness pipeline execution](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yshgvevwiudvj184ir1t.png) |
|-|

__Congratulations, you just imported a repository and ran a pipeline!__ :tada:

In this tutorial, we have just scratched the surface of what is possible with Gitness 😄

## Next Steps

- Create [triggers](https://docs.gitness.com/pipelines/triggers) to automatically run the pipeline on certain events
- Define [conditions](https://docs.gitness.com/pipelines/conditions) to only run specific steps for certain events
- Set values dynamically at runtime with [expressions](https://docs.gitness.com/pipelines/expressions)
- Review [samples](https://docs.gitness.com/category/samples) for other languages and write some pipelines of your own!

## Resources

- [Gitness website](https://gitness.com?utm_source=dev.to&utm_content=blog&utm_medium=blog&utm_term=gitness-build-and-test-golang-app)
- [Gitness documentation](https://docs.gitness.com)
- [Gitness GitHub repository](https://github.com/harness/gitness)
- [Harness Community Slack](https://docs.gitness.com/support#slack)

Cover image by <a href="https://unsplash.com/@josholalde?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash">Josh Olalde</a> on <a href="https://unsplash.com/photos/X1P1_EDNnok?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash">Unsplash</a>