2019-06-04 12:12:11 +00:00
|
|
|
Param(
|
|
|
|
[string] $GuardianCliLocation,
|
|
|
|
[string] $WorkingDirectory,
|
|
|
|
[string] $TargetDirectory,
|
|
|
|
[string] $GdnFolder,
|
|
|
|
[string[]] $ToolsList,
|
|
|
|
[string] $UpdateBaseline,
|
2019-11-22 13:41:58 +00:00
|
|
|
[string] $GuardianLoggerLevel='Standard',
|
2019-07-04 12:24:43 +00:00
|
|
|
[string[]] $CrScanAdditionalRunConfigParams,
|
|
|
|
[string[]] $PoliCheckAdditionalRunConfigParams
|
2019-06-04 12:12:11 +00:00
|
|
|
)
|
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
$ErrorActionPreference = 'Stop'
|
2019-06-04 12:12:11 +00:00
|
|
|
Set-StrictMode -Version 2.0
|
2019-11-22 13:41:58 +00:00
|
|
|
$disableConfigureToolsetImport = $true
|
2019-06-04 12:12:11 +00:00
|
|
|
$LASTEXITCODE = 0
|
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
try {
|
2020-03-31 13:04:58 +00:00
|
|
|
# `tools.ps1` checks $ci to perform some actions. Since the SDL
|
|
|
|
# scripts don't necessarily execute in the same agent that run the
|
|
|
|
# build.ps1/sh script this variable isn't automatically set.
|
|
|
|
$ci = $true
|
2019-11-22 13:41:58 +00:00
|
|
|
. $PSScriptRoot\..\tools.ps1
|
2019-06-04 12:12:11 +00:00
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
# We store config files in the r directory of .gdn
|
|
|
|
Write-Host $ToolsList
|
|
|
|
$gdnConfigPath = Join-Path $GdnFolder 'r'
|
|
|
|
$ValidPath = Test-Path $GuardianCliLocation
|
2019-06-04 12:12:11 +00:00
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
if ($ValidPath -eq $False)
|
|
|
|
{
|
|
|
|
Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Invalid Guardian CLI Location."
|
|
|
|
ExitWithExitCode 1
|
2019-06-04 12:12:11 +00:00
|
|
|
}
|
2019-11-22 13:41:58 +00:00
|
|
|
|
|
|
|
$configParam = @('--config')
|
|
|
|
|
|
|
|
foreach ($tool in $ToolsList) {
|
|
|
|
$gdnConfigFile = Join-Path $gdnConfigPath "$tool-configure.gdnconfig"
|
|
|
|
Write-Host $tool
|
|
|
|
# We have to manually configure tools that run on source to look at the source directory only
|
|
|
|
if ($tool -eq 'credscan') {
|
|
|
|
Write-Host "$GuardianCliLocation configure --working-directory $WorkingDirectory --tool $tool --output-path $gdnConfigFile --logger-level $GuardianLoggerLevel --noninteractive --force --args `" TargetDirectory < $TargetDirectory `" `" OutputType < pre `" $(If ($CrScanAdditionalRunConfigParams) {$CrScanAdditionalRunConfigParams})"
|
|
|
|
& $GuardianCliLocation configure --working-directory $WorkingDirectory --tool $tool --output-path $gdnConfigFile --logger-level $GuardianLoggerLevel --noninteractive --force --args " TargetDirectory < $TargetDirectory " "OutputType < pre" $(If ($CrScanAdditionalRunConfigParams) {$CrScanAdditionalRunConfigParams})
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
|
|
Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Guardian configure for $tool failed with exit code $LASTEXITCODE."
|
|
|
|
ExitWithExitCode $LASTEXITCODE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($tool -eq 'policheck') {
|
|
|
|
Write-Host "$GuardianCliLocation configure --working-directory $WorkingDirectory --tool $tool --output-path $gdnConfigFile --logger-level $GuardianLoggerLevel --noninteractive --force --args `" Target < $TargetDirectory `" $(If ($PoliCheckAdditionalRunConfigParams) {$PoliCheckAdditionalRunConfigParams})"
|
|
|
|
& $GuardianCliLocation configure --working-directory $WorkingDirectory --tool $tool --output-path $gdnConfigFile --logger-level $GuardianLoggerLevel --noninteractive --force --args " Target < $TargetDirectory " $(If ($PoliCheckAdditionalRunConfigParams) {$PoliCheckAdditionalRunConfigParams})
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
|
|
Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Guardian configure for $tool failed with exit code $LASTEXITCODE."
|
|
|
|
ExitWithExitCode $LASTEXITCODE
|
|
|
|
}
|
2019-06-04 12:12:11 +00:00
|
|
|
}
|
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
$configParam+=$gdnConfigFile
|
|
|
|
}
|
2019-06-04 12:12:11 +00:00
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-Host "$GuardianCliLocation run --working-directory $WorkingDirectory --baseline mainbaseline --update-baseline $UpdateBaseline --logger-level $GuardianLoggerLevel $configParam"
|
|
|
|
& $GuardianCliLocation run --working-directory $WorkingDirectory --tool $tool --baseline mainbaseline --update-baseline $UpdateBaseline --logger-level $GuardianLoggerLevel $configParam
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
|
|
Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Guardian run for $ToolsList using $configParam failed with exit code $LASTEXITCODE."
|
|
|
|
ExitWithExitCode $LASTEXITCODE
|
|
|
|
}
|
2019-08-30 12:32:56 +00:00
|
|
|
}
|
2019-11-22 13:41:58 +00:00
|
|
|
catch {
|
|
|
|
Write-Host $_.ScriptStackTrace
|
2020-03-31 13:04:58 +00:00
|
|
|
Write-PipelineTelemetryError -Force -Category 'Sdl' -Message $_
|
2019-11-22 13:41:58 +00:00
|
|
|
ExitWithExitCode 1
|
2020-03-31 13:04:58 +00:00
|
|
|
}
|