AzOps-Accelerator/.pipelines/redeploy.yml

109 строки
2.8 KiB
YAML

---
name: "AzOps - Redeploy"
parameters:
- name: path
displayName: Path with templates that will be deployed
type: string
#
# Triggers
# Automated triggers are disabled for the Redeploy pipeline
#
trigger: none
variables:
#
# Shared variables
# Include shared variables from the 'vars.yml' file
# to not have to repeat them in every pipeline.
#
- template: .templates/vars.yml
jobs:
- job: redeploy
#
# Redeploy
# This job will redeploy all the templates in the given path
#
displayName: "Redeploy"
pool:
vmImage: ubuntu-20.04
steps:
#
# Shared steps
# Include shared steps from the 'shared.yml' file
# to not have to repeat them in every pipeline.
#
- template: .templates/sharedSteps.yml
#
# Diff
# Get all files in the given path
#
- task: PowerShell@2
displayName: "List files"
inputs:
targetType: "inline"
script: |
$Path = '${{ parameters.path }}'
if ( -not (Test-Path -Path $Path)) {
Write-Host "##[error]The path $Path does not exist"
exit 1
}
$PathItem = Get-Item -Path $Path
if ($PathItem.PSISContainer) {
$gitDiff = Get-ChildItem $Path -File | Resolve-Path -Relative | ForEach-Object -MemberName Insert -ArgumentList 0, "M`t"
}
else {
$gitDiff = $PathItem.FullName | Resolve-Path -Relative | ForEach-Object -MemberName Insert -ArgumentList 0, "M`t"
}
if ($null -ne $gitDiff) {
$gitDiff | Write-Host
$gitDiff | Out-File -FilePath '/tmp/diff.txt'
}
else {
Write-Host '##[error]The validation pipeline failed because there is currently no change to be processed'
exit 1
}
#
# CustomSorting
# If CustomSorting is enabled, sort files in diff by the .order file in each directory
#
- task: PowerShell@2
displayName: "CustomSorting"
condition: eq(variables['AZOPS_CUSTOM_SORT_ORDER'],'true')
inputs:
targetType: "filePath"
filePath: ".scripts/customSorting.ps1"
#
# Deploy
# Deploy all templates in path.
#
- task: PowerShell@2
displayName: "Deploy"
inputs:
targetType: "inline"
script: |
$Env:PSModulePath = $Env:PSModulePath, '$(modulesFolder)' -join [IO.Path]::PathSeparator
$CustomSortOrder = $Env:AZOPS_CUSTOM_SORT_ORDER -eq 'true'
Import-PSFConfig -Path settings.json -Schema MetaJson -EnableException
$diff = Get-Content -Path /tmp/diff.txt
Invoke-AzOpsPush -ChangeSet $diff -CustomSortOrder:$CustomSortOrder
Get-Job | Remove-Job -Force