PSRule.Rules.Azure/.azure-pipelines/azure-pipelines.yaml

174 строки
4.8 KiB
YAML

# Azure DevOps
# CI pipeline for PSRule.Rules.Azure
variables:
version: '1.15.0'
buildConfiguration: 'Release'
disable.coverage.autogenerate: 'true'
imageName: 'ubuntu-20.04'
# Use build number format, i.e. 1.15.0-B2202001
name: $(version)-B$(date:yyMM)$(rev:rrr)
trigger:
branches:
include:
- 'main'
- 'release/*'
pr:
branches:
include:
- 'main'
- 'release/*'
stages:
# Build pipeline
- stage: Build
displayName: Build
dependsOn: []
jobs:
- job:
pool:
vmImage: $(imageName)
displayName: 'Module'
steps:
# Install pipeline dependencies
- powershell: ./.azure-pipelines/pipeline-deps.ps1
displayName: 'Install dependencies'
# Build module
- powershell: Invoke-Build -Configuration $(buildConfiguration) -Build $(Build.BuildNumber)
displayName: 'Build module'
# DotNet test results
- task: PublishTestResults@2
displayName: 'Publish unit test results'
inputs:
testRunTitle: 'DotNet on $(imageName)'
testRunner: VSTest
testResultsFiles: 'reports/*.trx'
mergeTestResults: true
platform: $(imageName)
configuration: $(buildConfiguration)
publishRunAttachments: true
condition: succeededOrFailed()
# PSRule results
- task: PublishTestResults@2
displayName: 'Publish PSRule results'
inputs:
testRunTitle: 'PSRule on $(imageName)'
testRunner: NUnit
testResultsFiles: 'reports/ps-rule*.xml'
mergeTestResults: true
platform: $(imageName)
configuration: $(buildConfiguration)
publishRunAttachments: true
condition: succeededOrFailed()
# Generate artifacts
- publish: out/modules/PSRule.Rules.Azure
displayName: 'Publish module'
artifact: PSRule.Rules.Azure
# Analysis pipeline
- stage: Analysis
displayName: Analysis
dependsOn: []
variables:
skipComponentGovernanceDetection: true
jobs:
- job:
pool:
vmImage: $(imageName)
displayName: 'SonarCloud'
condition: not(eq(variables['Build.Reason'], 'PullRequest'))
steps:
- script: |
echo "##vso[task.setvariable variable=JAVA_HOME]$(JAVA_HOME_11_X64)"
echo "##vso[task.setvariable variable=PATH]$(JAVA_HOME_11_X64)\bin;$(PATH)"
displayName: 'Set Java version'
# Run SonarCloud analysis
- script: dotnet tool install --global dotnet-sonarscanner
displayName: 'Install Sonar scanner'
- script: $HOME/.dotnet/tools/dotnet-sonarscanner begin /k:"BernieWhite_PSRule_Rules_Azure" /o:"berniewhite-github" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login=$(sonarQubeToken) /v:"$(Build.BuildNumber)" /d:sonar.cs.vscoveragexml.reportsPaths="reports/" /d:sonar.cs.xunit.reportsPaths="reports/"
displayName: 'Prepare SonarCloud'
- script: dotnet build
displayName: 'Build solution for analysis'
- script: $HOME/.dotnet/tools/dotnet-sonarscanner end /d:sonar.login=$(sonarQubeToken)
displayName: 'Complete SonarCloud'
- job: Secret_Scan
pool:
vmImage: 'windows-2019'
displayName: Secret scan
steps:
- task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@2
displayName: 'Scan for secrets'
inputs:
debugMode: false
toolMajorVersion: V2
- task: securedevelopmentteam.vss-secure-development-tools.build-task-publishsecurityanalysislogs.PublishSecurityAnalysisLogs@2
displayName: 'Publish scan logs'
continueOnError: true
- task: securedevelopmentteam.vss-secure-development-tools.build-task-postanalysis.PostAnalysis@1
displayName: 'Check for failures'
inputs:
CredScan: true
ToolLogsNotFoundAction: Error
# Test pipeline
- stage: Test
dependsOn: Build
jobs:
- template: jobs/test.yaml
parameters:
name: ubuntu_20_04_coverage
imageName: 'ubuntu-20.04'
displayName: 'PowerShell coverage'
coverage: 'true'
publishResults: 'false'
platform: linux
bicepIntegration: 'true'
- template: jobs/test.yaml
parameters:
name: macOS_10_15
displayName: 'PowerShell 7.1 - macOS-10.15'
imageName: 'macOS-10.15'
platform: macos
- template: jobs/test.yaml
parameters:
name: ps_5_1_windows_2019
displayName: 'PowerShell 5.1 - Windows 2019'
imageName: 'windows-2019'
platform: windows
pwsh: 'false'
- template: jobs/test.yaml
parameters:
name: ps_7_2_windows_2019
displayName: 'PowerShell 7.2 - Windows 2019'
imageName: 'windows-2019'
platform: windows
pwsh: 'true'
- template: jobs/testContainer.yaml
parameters:
name: ps_7_2_ubuntu_20_04
displayName: 'PowerShell 7.2 - ubuntu-20.04'
imageName: mcr.microsoft.com/powershell
imageTag: 7.2.2-ubuntu-20.04