# CircleCI

### Common Build Integration Documentation

This documentation is specific to CircleCI. [Common build server](https://docs.threatrix.io/integrations/build-integrations) documentation should be reviewed before proceeding further.&#x20;

### Environment Variables

Environment variable values can be found in your [user profile](https://docs.threatrix.io/threat-center-1/user-profile).

* THREATRIX\_OID - Your organization ID.
* THREATRIX\_EID - Your entityID (if you wish to override your default).
* THREATRIX\_API\_KEY - Personal or organization API key.

### Install Environment Variables

{% hint style="warning" %}
This step may require administrative privileges within CircleCI
{% endhint %}

From within CircleCI navigate to "Organization Settings->Contexts"

<figure><img src="https://3093892275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbsieSiu0D66DBFP4uh%2Fuploads%2FbfnjqVjN1oecvS5DYBMe%2Fimage.png?alt=media&#x26;token=0bd530c2-d7c5-4d03-889a-9b53394313ee" alt=""><figcaption></figcaption></figure>

Click the Create Context button and create a new Context named "Threatrix"

<figure><img src="https://3093892275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbsieSiu0D66DBFP4uh%2Fuploads%2F0FJ1cC6aiUnr5pGn5tff%2Fimage.png?alt=media&#x26;token=f421555b-33e6-42e7-8195-44bb682ec352" alt=""><figcaption></figcaption></figure>

After creating the context, click on the name to add environment variables to the context.&#x20;

<figure><img src="https://3093892275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbsieSiu0D66DBFP4uh%2Fuploads%2Flv5OhTfU2TLUidF7qMKj%2Fimage.png?alt=media&#x26;token=a98fba40-5155-4b3a-8356-8fb3971e3d3a" alt=""><figcaption></figcaption></figure>

From within the Add Environment Variable dialog, enter the necessary variable values.

* THREATRIX\_OID - Your organization ID.
* THREATRIX\_EID - Your entityID (if you wish to override your default).
* THREATRIX\_API\_KEY - Personal or organization API key.

![](https://3093892275-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MbsieSiu0D66DBFP4uh%2F-Mj1iY3Spbt-qktKehvg%2F-Mj1ivZuQ0d6E6m2aF26%2Fimage.png?alt=media\&token=0d58cd5c-92ee-46fc-833b-1fe9bdbd0b65)

## Add the Threatrix Agent to your build server.&#x20;

First,Add threatrix context to your job

<figure><img src="https://3093892275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbsieSiu0D66DBFP4uh%2Fuploads%2FzRrb2eMRq4NBqUCFUn1A%2Fimage.png?alt=media&#x26;token=db6a53cd-8039-4bfb-a621-6a4f1ce63c71" alt=""><figcaption></figcaption></figure>

### Option 1: Add CLI Threat Agent

From within your SCM repository, add the following snippet to your .circleci/config.yml file or download a full example here:&#x20;

{% file src="<https://3093892275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbsieSiu0D66DBFP4uh%2Fuploads%2FK3Otn6shQTXdyJ7fpLzk%2Fconfig.yml?alt=media&token=85c22d62-13de-4850-b8ff-fce59a1db8d1>" %}
config.yml
{% endfile %}

```yaml
# Execute Threat Scan
- run:
    name: Install Threatrix ThreatAgent & Scan
    command: |
        curl -LJO https://github.com/threatrix/threat-matrix/releases/download/agent-release-latest/threat-agent-latest.jar
        java -jar /tmp/threatagent.jar --progress
        
```

### Option 2: Add Docker Threat Agent Step to your build

{% hint style="warning" %}
**Prerequisite: In order to use our Docker image, your build executor must be of type `machine` otherwise, we'll be unable to create the necessary Docker volume**
{% endhint %}

<figure><img src="https://3093892275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbsieSiu0D66DBFP4uh%2Fuploads%2FnCZ6MEPHU4cPsl1dWX4q%2Fimage.png?alt=media&#x26;token=8e10f5cd-fad4-415f-844e-5ea57c8cdd58" alt=""><figcaption></figcaption></figure>

Add the following code snippet as a step to your existing build job. The threatrix scan agent should run either before or in parallel with your build job.

```
- run:
    name: Threatrix Scan
    command: |
        printenv > host.env
        docker run -v $(pwd):/app --env-file=host.env threatrix/threat-agent ./
```
