> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/application-security/application-security/onboard-data-sources/ingest-third-party-data-sources/generic-3rd-party-appsec-collector/upload-findings-from-ci-cd-pipelines.md).

# Upload findings from CI/CD pipelines

Upload findings via the API from CI/CD pipelines to automate ingestion at the CI stage.

{% hint style="info" %}

### Note

Store all collector credentials (Token ID, API Token, API URL) as encrypted secrets or credentials in the CI/CD platform. Do not hardcode credentials in pipeline configuration files.
{% endhint %}

The following examples demonstrate common integration patterns.

{% hint style="info" %}

### Important

Verify that the upload request returns a `2xx` HTTP status code. A `non-2xx` response indicates that the upload failed and findings were not ingested. Configure the CI/CD pipeline step to fail on `non-2xx` responses to prevent silent ingestion failures. In the cURL examples, add the `--fail` flag or check the exit code to detect upload failures.
{% endhint %}

**GitHub Actions**

```programlisting
name: Upload SAST Findings to Cortex Cloud

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

jobs:
  scan-and-upload:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Run SAST scanner
        run: |
          # Replace with your SAST tool command
          bandit -r src/ -f sarif -o sarif-results.json

      - name: Upload findings to Cortex Cloud
        env:
          CORTEX_TOKEN_ID: ${{ secrets.CORTEX_COLLECTOR_TOKEN_ID }}
          CORTEX_API_TOKEN: ${{ secrets.CORTEX_COLLECTOR_API_TOKEN }}
          CORTEX_API_URL: ${{ secrets.CORTEX_COLLECTOR_API_URL }}
          CORTEX_REPO_ID: ${{ secrets.CORTEX_REPOSITORY_ID }}
        run: |
          curl -X POST "${CORTEX_API_URL}?repository_id=${CORTEX_REPO_ID}&branch=${GITHUB_REF_NAME}" \
            -H "x-crtx-auth-id: ${CORTEX_TOKEN_ID}" \
            -H "Authorization: ${CORTEX_API_TOKEN}" \
            -H "Content-Type: application/json" \
            -d @sarif-results.json
```

**GitLab CI**

```programlisting
upload-sast-findings:
  stage: test
  script:
    # Replace with your SAST tool command
    - bandit -r src/ -f sarif -o sarif-results.json
    - |
      curl -X POST "${CORTEX_API_URL}?repository_id=${CORTEX_REPO_ID}&branch=${CI_COMMIT_REF_NAME}" \
        -H "x-crtx-auth-id: ${CORTEX_TOKEN_ID}" \
        -H "Authorization: ${CORTEX_API_TOKEN}" \
        -H "Content-Type: application/json" \
        -d @sarif-results.json
  variables:
    CORTEX_TOKEN_ID: ${CORTEX_COLLECTOR_TOKEN_ID}
    CORTEX_API_TOKEN: ${CORTEX_COLLECTOR_API_TOKEN}
    CORTEX_API_URL: ${CORTEX_COLLECTOR_API_URL}
    CORTEX_REPO_ID: ${CORTEX_REPOSITORY_ID}
```

**Jenkins (Declarative Pipeline)**

```programlisting
pipeline {
    agent any
    environment {
        CORTEX_TOKEN_ID     = credentials('cortex-collector-token-id')
        CORTEX_API_TOKEN    = credentials('cortex-collector-api-token')
        CORTEX_API_URL      = credentials('cortex-collector-api-url')
        CORTEX_REPO_ID      = credentials('cortex-repository-id')
    }
    stages {
        stage('SAST Scan') {
            steps {
                // Replace with your SAST tool command
                sh 'bandit -r src/ -f sarif -o sarif-results.json'
            }
        }
        stage('Upload to Cortex Cloud') {
            steps {
                sh """
                    curl -X POST "${CORTEX_API_URL}?repository_id=${CORTEX_REPO_ID}&branch=${env.BRANCH_NAME}" \
                      -H "x-crtx-auth-id: ${CORTEX_TOKEN_ID}" \
                      -H "Authorization: ${CORTEX_API_TOKEN}" \
                      -H "Content-Type: application/json" \
                      -d @sarif-results.json
                """
            }
        }
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://cortex-docs.paloaltonetworks.com/application-security/application-security/onboard-data-sources/ingest-third-party-data-sources/generic-3rd-party-appsec-collector/upload-findings-from-ci-cd-pipelines.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
