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 17 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
that-ar-guy marked this conversation as resolved.
Show resolved Hide resolved
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