# Making our CI/CD Pipeline

### Config File

To create our pipeline, we must first create a `.gitlab-ci.yml` file and specify it to our project requirements (Place this in your project root)

[Templates](https://docs.gitlab.com/ee/ci/examples/)

[Syntax Reference](https://docs.gitlab.com/ee/ci/yaml/)

{% code title=".gitlab-ci.yml" %}

```yaml
image: golang:1.22  

stages:
  - test
  - build

build:
  stage: build
  script:
    - "go build -o calculator"
    - "./calculator"

test:
  stage: test
  script:
    - "go test"
```

{% endcode %}

Paste the code then push it to your repository

```bash
> git add .\.gitlab-ci.yml 
> git commit -m "Created GO Pipeline"
> git push
```

We can now view our pipeline from the repository, under **Build -> Pipeline -> Pipeline Number**

### **Viewing our deployed pipeline**

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FJhar8wpqgYJ3pSesV83D%2Fimage.png?alt=media&#x26;token=1a2e6944-f93c-4450-986f-0d1bf550f5e8" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2F7nlq3r5PNVCG39hPiuu5%2Fimage.png?alt=media&#x26;token=fd232bab-0e92-4e3f-9b0a-d21f0a4d4db0" alt=""><figcaption><p>Successful Build</p></figcaption></figure>

{% hint style="warning" %}
**Issues Faced**

Spent the better part of an hour debugging and figured out that you need to create a runner as root cause of docker permissions. Alternatively, you can add yourself to the docker group - although it's easier just to use sudo
{% endhint %}

### Testing for Failures

Just like in [simple-calculator-project](https://blog.securescape.cc/offensive-security/red-team/offensive-development/offensive-devops/gitlab/simple-calculator-project "mention"), we can test for failures by changing the values slightly

First, we'll create a separate branch to mimic a real project, then change the test values from there

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FZoJSOkKFt3ayptk1JQfk%2Fimage.png?alt=media&#x26;token=8d2d0258-1e29-438f-813e-ff3c047059b1" alt=""><figcaption><p>Creating a new branch with VS Code</p></figcaption></figure>

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FBRJdPjXXI1n2MaRg6pi7%2Fimage.png?alt=media&#x26;token=04872a25-7a26-4e81-bbb9-81e960171372" alt=""><figcaption><p>Editing calculator_test.go</p></figcaption></figure>

Push your changes then wait for the pipeline to finish running

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FYxtscEBGzYnFx6TvaJFc%2Fimage.png?alt=media&#x26;token=f6d2fffe-57d2-4b5c-a1aa-6972202dbf71" alt=""><figcaption><p>Failure Test</p></figcaption></figure>

We can now fix it back and create a merge request to main. Merge requests will trigger a pipeline job to check for errors before letting you merge (depending on your project settings)

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FS8gkXpRRm5dj42EyvWKN%2Fimage.png?alt=media&#x26;token=f194b864-da2b-4662-b148-5492fb92f52d" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blog.securescape.cc/offensive-security/red-team/offensive-development/offensive-devops/gitlab/making-our-ci-cd-pipeline.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
