# CircleCI

{% hint style="info" %}
Cortex connects to many third-party vendors whose system interfaces frequently change. As a result, integration behavior or configuration steps may shift without notice. If you encounter unexpected issues, check with your system administrator or refer to the vendor's documentation for the most current information. Additionally, integration sync times vary and are subject to scheduling overrides and timing variance.
{% endhint %}

[CircleCI](https://circleci.com/) is continuous integration and continuous delivery platform that can be used to implement DevOps best practices.

Integrating CircleCI with Cortex allows you to:

* [View information about CircleCI workflows and pipelines on entity pages](#viewing-circleci-information-on-entity-pages) in Cortex
* Create [Scorecards](https://docs.cortex.io/standardize/scorecards) that track progress and drive alignment on projects involving your CircleCI data

## How to configure CircleCI with Cortex

### Prerequisites

Before getting started:

* Create a [CircleCI API token](https://circleci.com/docs/managing-api-tokens/).

**Self-hosted CircleCI instances**

If you’re using a self-hosted instance of CircleCI, you’ll need to verify that your Cortex instance is able to reach the CircleCI instance.\
\
We route our requests through a static IP address. Reach out to support at <help@cortex.io> to receive details about our static IP. If you're unable to directly allowlist our static IP, you can route requests through a secondary proxy in your network that has this IP allowlisted and have that proxy route traffic to your CircleCI instance.

### Configure the integration in Cortex

1. In Cortex, navigate to the [CircleCI settings page](https://app.getcortexapp.com/admin/integrations/circleci).
   * Click **Integrations** from the main nav. Search for and select **CircleCI**.
2. Click **Add configuration**.
3. Configure the integration form:
   * **Account alias**: Enter an alias for this integration, used to tie entity registrations to different configurations.
   * **API token**: Enter the value of the API token you created in CircleCI.
   * **Host**: Enter the URL for your CircleCI instance if self-hosted, e.g., `https://cortex.circleci.com`
4. Click **Save**.

**Configure the integration for multiple CircleCI accounts**[**​**](https://docs.cortex.io/docs/reference/integrations/circleci#configure-the-integration-for-multiple-propsintegration-accounts)

The CircleCI integration has multi-account support. You can add a configuration for each additional by repeating the process above.

Each configuration requires an alias, which Cortex uses to correlate the designated with registrations for various entities. Registrations can also use a default configuration without a listed alias. You can edit aliases and default configurations from the CircleCI page in your Cortex settings. Select the edit icon next to a given configuration and toggle **Set as default** on. If you only have one configuration, it will automatically be set as the default.

## How to connect Cortex entities to CircleCI

### Editing the entity descriptor

You can define CircleCI projects in an [entity's YAML descriptor](https://docs.cortex.io/entities#defining-entities-via-yaml-file). Add its project slug under the `x-cortex-circle-ci` block:

```yaml
x-cortex-circle-ci:
  projects:
    - projectSlug: circleci-projectslug # projectslug in CircleCI
      alias: circleci-alias # alias is optional and only relevant if you have opted into multi account support
```

## Using the CircleCI integration

### Viewing CircleCI information on entity pages

When an entity has a CircleCI project defined in its YAML file, you will see metric and pipeline details on an [entity's details page](https://docs.cortex.io/ingesting-data-into-cortex/entities/details). Click **CI/CD > CircleCI** in the entity's sidebar to see this information.

### Scorecards and CQL

With the CircleCI integration, you can create Scorecard rules and write CQL queries based on CircleCI metrics and pipelines.

See more examples in the [CQL Explorer](https://app.getcortexapp.com/admin/cql-explorer) in Cortex.

<details>

<summary>Check for CircleCI flaky tests</summary>

Get all Circle CI flaky tests associated with the entity.

**Definition**: `circleci.flakyTests()`

**Example**

You could create a Scorecard with a rule that verifies no flaky tests:

```
circleci.flakyTests().length == 0
```

</details>

<details>

<summary>Get Circle CI projects</summary>

Get all Circle CI projects associated with the entity.

**Definition**: `circleci.projects()`

**Example**

You could also create a rule that checks for a success rate over 90%:

```
circleci.projects().all((project) => project.metrics.successRate > 0.9) == true
```

</details>

### View integration logs <a href="#still-need-help" id="still-need-help"></a>

## Still need help?[​](https://docs.cortex.io/docs/reference/integrations/aws#still-need-help) <a href="#still-need-help" id="still-need-help"></a>

The following options are available to get assistance from the Cortex Customer Engineering team:

* **Email**: <help@cortex.io>, or open a support ticket in the in app Resource Center
* **Slack**: Users with a connected Slack channel will have a workflow added to their account. From here, you can either @CortexTechnicalSupport or add a `:ticket:` reaction to a question in Slack, and the team will respond directly.

Don’t have a Slack channel? Talk with your Customer Success Manager.


---

# 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://docs.cortex.io/ingesting-data-into-cortex/integrations/circleci.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.
