Core/PipelinesRunner-Module.psm1
$ErrorActionPreference = "Stop" function RemoveTemp { if (Test-Path "$SAFTempDir") { Remove-Item "$SAFTempDir" -Recurse -Force | Out-Null } } function CreateTemp { if (!(Test-Path "$SAFTempDir")) { New-Item -ItemType Directory -Path "$SAFTempDir" -Force | Out-Null } } function GetPipelineSteps { [CmdletBinding()] Param ( [string]$DefinitionFile, [string]$Name, [switch]$RunExtensions ) $pipelines = Get-Content -Raw -Path $DefinitionFile | ConvertFrom-Json $steps = $pipelines.$Name if (($RunExtensions.IsPresent) -and ($null -ne $SAFConfiguration.Extensions.Pipelines)) { $steps += $SAFConfiguration.Extensions.Pipelines } return $steps } function BuildStepAbsolutePath { [CmdletBinding()] Param ( [string]$Path ) if (!($Path.StartsWith("/") -or $Path.StartsWith("\"))) { return $Path } $absPath = "$(Get-Location)$Path" if (Test-Path $absPath) { return $absPath } return "$PSScriptRoot\..\Pipelines\Steps$Path" } function IsXM { return ($SAFConfiguration.system.sitecoreMode -eq "XM") } function ShouldSkip { [CmdletBinding()] Param ( [object]$Step ) $skip = $false if (!($null -eq $Step.skip)) { if($Step.skip -eq $true){ $skip = $true } else { $skip = Invoke-Expression $Step.skip } } return $skip } function ShowSteps { [CmdletBinding()] Param ( [string]$Pipeline, [PSObject[]]$Steps ) Write-Output "`n`nSAF will run '$Pipeline' pipeline:`n" foreach ($step in $Steps) { if(ShouldSkip -Step $step) { } elseif (IsStepCompleted -Pipeline $Pipeline -Step $step.name) { Write-Warning "SKIP $($step.name)" } else { Write-Output "- $($step.name)" } } Write-Output "" Write-Output "Starting after 13 seconds..." Write-Output "" Start-Sleep -s 13 } function RunPipeline { [CmdletBinding()] Param ( [string]$DefinitionFile, [string]$Name, [switch]$Force, [switch]$RunExtensions ) CreateTemp if ($Force.IsPresent) { EraseHistoryLog -Pipeline $Name } $steps = GetPipelineSteps -DefinitionFile $DefinitionFile -Name $Name -RunExtensions:$RunExtensions ShowSteps -Pipeline $Name -Steps $steps try { foreach ($step in $steps) { if ((ShouldSkip -Step $step) -or (IsStepCompleted -Pipeline $Name -Step $step.name)) { continue } $stepAbsPath = BuildStepAbsolutePath -Path $step.script & $stepAbsPath MarkStepAsCompleted -Pipeline $Name -Step $step.name } RemoveTemp } catch { $exception = $_.Exception | Format-List -Force | Out-String Write-Error $exception } } Export-ModuleMember -Function "RunPipeline" Export-ModuleMember -Function "RemoveTemp" |