Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs/quickstart for ado #3220

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
73 changes: 73 additions & 0 deletions docs/quickstarts/quickstart-for-ado.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Quickstart: Use PSRule for Azure with Azure DevOps

This quickstart guide will help you set up PSRule for Azure in an Azure DevOps pipeline to validate Infrastructure as Code (IaC) templates, such as ARM or Bicep files. By the end, you will have a pipeline that installs and runs PSRule, validates IaC templates, and publishes validation results in Azure DevOps Test Reports.

## Prerequisites
that-ar-guy marked this conversation as resolved.
Show resolved Hide resolved

1. **Azure DevOps account:** You need an Azure DevOps organization with an active project.
2. **IaC templates:** Ensure you have ARM or Bicep templates in your repository for validation.
3. **Agent pool:** An agent pool must be configured to execute pipelines. Use a self-hosted agent if needed.
4. **PowerShell Core:** Your build agent should have PowerShell Core installed (v7 or later).
5. **PSRule module:** The PSRule module will be installed during pipeline execution.

---
that-ar-guy marked this conversation as resolved.
Show resolved Hide resolved

that-ar-guy marked this conversation as resolved.
Show resolved Hide resolved
## Steps to Create the Pipeline

### Step 1: Add a Pipeline YAML File

Create a new file named `azure-pipeline.yml` in the root of your repository. This file defines the pipeline steps.

### Step 2: Define the Pipeline

Add the following content to your `azure-pipeline.yml` file:

```yaml
trigger:
- main

pool:
vmImage: 'ubuntu-latest'

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'

- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
Install-Module -Name PSRule.Rules.Azure -Force -Scope CurrentUser
pwsh -Command "Invoke-PSRule -InputPath './templates'"
that-ar-guy marked this conversation as resolved.
Show resolved Hide resolved

- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Publishing results in NUnit would require configuring ps-rule.yaml or setting options via environment variables. Also expansion needs to be enabled.

We should add something similar to: https://azure.github.io/PSRule.Rules.Azure/quickstarts/test-bicep-with-github/#create-an-options-file

Maybe you can use the same markdown and add the adjustments for outputting results by setting options for Output.Format and Output.Path into ps-rule.yaml.

https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Options/#outputpath

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before I proceed with the updates, I’d like to confirm if I’m heading in the right direction:

  1. Switch to NUnit for Test Results:
    Should I update the pipeline to use NUnit instead of JUnit for publishing results? I’ll also ensure the results are outputted to .psrule-output/results.xml.

  2. Update ps-rule.yaml Configuration:
    You mentioned configuring the ps-rule.yaml file. I plan to include the following settings:

    • Output.Format: NUnit
    • Output.Path: .psrule-output/results.xml
    • Expand: true to enable detailed rule explanations.
  3. Documentation Update:
    I’ll update the quickstart guide to explain how to configure the ps-rule.yaml file with these settings, and also reference the relevant PSRule documentation.

Is that aligned with what you were expecting?

testResultsFiles: '**/psrule-results.xml'
```

### Step 3: Commit and Push

1. Commit your changes to the repository:
```bash
git add azure-pipeline.yml
git commit -m "Add Azure DevOps pipeline for PSRule validation"
git push origin main
```

2. The pipeline will automatically trigger and validate your templates.

---

## Reviewing Validation Results

1. Go to your Azure DevOps project.
2. Open the **Pipelines** section and view the pipeline run.
3. Look for validation output in the logs and **Test Results**.
4. Fix any reported issues in your IaC templates to pass validation.

---

For more information about PSRule for Azure, visit the [official documentation](https://azure.github.io/PSRule.Rules.Azure/).

Loading