# Azure DevOps

> Run the Testsigma trigger script from an Azure Pipelines job and publish the JUnit results.

Azure DevOps triggers Testsigma test plans by running the shell script in a `Bash@3` pipeline task. A `PublishTestResults@2` task then publishes the JUnit report with the pipeline's other results.

## Prerequisites

- An [API key](https://testsigma.com/docs/v2/settings/developers/) and the test plan ID (**CI/CD Integrations** tab of the plan).

## Prepare the shell script

1. **Copy the script**: take the Unix shell script from the [shell script page](https://testsigma.com/docs/v2/integrations/ci-cd/shell-script/). On Windows, use the PowerShell script from the same page instead.

2. **Set the inputs**: replace `TESTSIGMA_API_KEY` and `TESTSIGMA_TEST_PLAN_ID` in the script with your values.

3. **Commit it**: save the script as `cicd-api.sh` in the code repository your pipeline will use.

The script triggers the test plan execution and returns the result once the run is complete.

## Create the pipeline

1. **Create a project**: sign in to your Azure DevOps account and create a **Project**.

2. **Start a pipeline**: navigate to **Pipelines** and click **New Pipeline**.

3. **Pick the source**: select the version control system, then the repository that contains `cicd-api.sh` and your configuration YAML file.

4. **Configure the YAML**: on the **Configure your pipeline** page, select **Existing Azure Pipelines YAML file** and enter its branch and path. No YAML yet? Select **Starter pipeline** and Azure DevOps creates a sample file in your repository once you grant access.

5. **Review and edit**: review the CI configuration and click **Continue**. Enter the path to `cicd-api.sh` in the `filePath` field:

    ```yaml title="azure-pipelines.yml"
    # Azure Pipelines YAML file
    trigger: master

    pool:
      vmImage: 'ubuntu-latest'

    steps:
    - script: echo Hello, world!
      displayName: Run a one-line script

    - task: Bash@3
      displayName: Run Shell Script (./cicd-api.sh)
      inputs:
        filePath: ./cicd-api.sh

    - task: PublishTestResults@2
      displayName: publish test-results
      inputs:
        testResultFormat: JUnit
        testResultsFiles: '**/*junit-report.xml'
    ```

## Run the pipeline and view results

1. **Run the job**: click **Run** and track it on the pipeline results page. The job status shows **Success** when it completes.

2. **View the reports**: navigate to **Test Plans > Runs**, then select the test plan whose report you want. Download the JUnit report in XML format from this page.

Use a separate shell script to convert the JUnit XML report into HTML format.
