77 [string ] $SourceDirectory = $env: BUILD_SOURCESDIRECTORY , # Required: the directory where source files are located
88 [string ] $ArtifactsDirectory = (Join-Path $env: BUILD_ARTIFACTSTAGINGDIRECTORY (' artifacts' )), # Required: the directory where build artifacts are located
99 [string ] $AzureDevOpsAccessToken , # Required: access token for dnceng; should be provided via KeyVault
10- [string []] $SourceToolsList , # Optional: list of SDL tools to run on source code
11- [string []] $ArtifactToolsList , # Optional: list of SDL tools to run on built artifacts
10+
11+ # Optional: list of SDL tools to run on source code. See 'configure-sdl-tool.ps1' for tools list
12+ # format.
13+ [object []] $SourceToolsList ,
14+ # Optional: list of SDL tools to run on built artifacts. See 'configure-sdl-tool.ps1' for tools
15+ # list format.
16+ [object []] $ArtifactToolsList ,
17+ # Optional: list of SDL tools to run without automatically specifying a target directory. See
18+ # 'configure-sdl-tool.ps1' for tools list format.
19+ [object []] $CustomToolsList ,
20+
1221 [bool ] $TsaPublish = $False , # Optional: true will publish results to TSA; only set to true after onboarding to TSA; TSA is the automated framework used to upload test results as bugs.
1322 [string ] $TsaBranchName = $env: BUILD_SOURCEBRANCH , # Optional: required for TSA publish; defaults to $(Build.SourceBranchName); TSA is the automated framework used to upload test results as bugs.
1423 [string ] $TsaRepositoryName = $env: BUILD_REPOSITORY_NAME , # Optional: TSA repository name; will be generated automatically if not submitted; TSA is the automated framework used to upload test results as bugs.
@@ -63,13 +72,16 @@ try {
6372 ExitWithExitCode 1
6473 }
6574
66- & $ (Join-Path $PSScriptRoot ' init-sdl.ps1' ) - GuardianCliLocation $guardianCliLocation - Repository $RepoName - BranchName $BranchName - WorkingDirectory $workingDirectory - AzureDevOpsAccessToken $AzureDevOpsAccessToken - GuardianLoggerLevel $GuardianLoggerLevel
75+ Exec- BlockVerbosely {
76+ & $ (Join-Path $PSScriptRoot ' init-sdl.ps1' ) - GuardianCliLocation $guardianCliLocation - Repository $RepoName - BranchName $BranchName - WorkingDirectory $workingDirectory - AzureDevOpsAccessToken $AzureDevOpsAccessToken - GuardianLoggerLevel $GuardianLoggerLevel
77+ }
6778 $gdnFolder = Join-Path $workingDirectory ' .gdn'
6879
6980 if ($TsaOnboard ) {
7081 if ($TsaCodebaseName -and $TsaNotificationEmail -and $TsaCodebaseAdmin -and $TsaBugAreaPath ) {
71- Write-Host " $guardianCliLocation tsa-onboard --codebase-name `" $TsaCodebaseName `" --notification-alias `" $TsaNotificationEmail `" --codebase-admin `" $TsaCodebaseAdmin `" --instance-url `" $TsaInstanceUrl `" --project-name `" $TsaProjectName `" --area-path `" $TsaBugAreaPath `" --iteration-path `" $TsaIterationPath `" --working-directory $workingDirectory --logger-level $GuardianLoggerLevel "
72- & $guardianCliLocation tsa- onboard -- codebase- name " $TsaCodebaseName " -- notification- alias " $TsaNotificationEmail " -- codebase- admin " $TsaCodebaseAdmin " -- instance- url " $TsaInstanceUrl " -- project- name " $TsaProjectName " -- area- path " $TsaBugAreaPath " -- iteration- path " $TsaIterationPath " -- working- directory $workingDirectory -- logger- level $GuardianLoggerLevel
82+ Exec- BlockVerbosely {
83+ & $guardianCliLocation tsa- onboard -- codebase- name " $TsaCodebaseName " -- notification- alias " $TsaNotificationEmail " -- codebase- admin " $TsaCodebaseAdmin " -- instance- url " $TsaInstanceUrl " -- project- name " $TsaProjectName " -- area- path " $TsaBugAreaPath " -- iteration- path " $TsaIterationPath " -- working- directory $workingDirectory -- logger- level $GuardianLoggerLevel
84+ }
7385 if ($LASTEXITCODE -ne 0 ) {
7486 Write-PipelineTelemetryError - Force - Category ' Sdl' - Message " Guardian tsa-onboard failed with exit code $LASTEXITCODE ."
7587 ExitWithExitCode $LASTEXITCODE
@@ -80,20 +92,51 @@ try {
8092 }
8193 }
8294
83- if ($ArtifactToolsList -and $ArtifactToolsList.Count -gt 0 ) {
84- & $ (Join-Path $PSScriptRoot ' run-sdl.ps1' ) - GuardianCliLocation $guardianCliLocation - WorkingDirectory $workingDirectory - TargetDirectory $ArtifactsDirectory - GdnFolder $gdnFolder - ToolsList $ArtifactToolsList - AzureDevOpsAccessToken $AzureDevOpsAccessToken - UpdateBaseline $UpdateBaseline - GuardianLoggerLevel $GuardianLoggerLevel - CrScanAdditionalRunConfigParams $CrScanAdditionalRunConfigParams - PoliCheckAdditionalRunConfigParams $PoliCheckAdditionalRunConfigParams
95+ # Configure a list of tools with a default target directory. Populates the ".gdn/r" directory.
96+ function Configure-ToolsList ([object []] $tools , [string ] $targetDirectory ) {
97+ if ($tools -and $tools.Count -gt 0 ) {
98+ Exec- BlockVerbosely {
99+ & $ (Join-Path $PSScriptRoot ' configure-sdl-tool.ps1' ) `
100+ - GuardianCliLocation $guardianCliLocation `
101+ - WorkingDirectory $workingDirectory `
102+ - TargetDirectory $targetDirectory `
103+ - GdnFolder $gdnFolder `
104+ - ToolsList $tools `
105+ - AzureDevOpsAccessToken $AzureDevOpsAccessToken `
106+ - GuardianLoggerLevel $GuardianLoggerLevel `
107+ - CrScanAdditionalRunConfigParams $CrScanAdditionalRunConfigParams `
108+ - PoliCheckAdditionalRunConfigParams $PoliCheckAdditionalRunConfigParams
109+ if ($BreakOnFailure ) {
110+ Exit-IfNZEC " Sdl"
111+ }
112+ }
113+ }
85114 }
86- if ($SourceToolsList -and $SourceToolsList.Count -gt 0 ) {
87- & $ (Join-Path $PSScriptRoot ' run-sdl.ps1' ) - GuardianCliLocation $guardianCliLocation - WorkingDirectory $workingDirectory - TargetDirectory $SourceDirectory - GdnFolder $gdnFolder - ToolsList $SourceToolsList - AzureDevOpsAccessToken $AzureDevOpsAccessToken - UpdateBaseline $UpdateBaseline - GuardianLoggerLevel $GuardianLoggerLevel - CrScanAdditionalRunConfigParams $CrScanAdditionalRunConfigParams - PoliCheckAdditionalRunConfigParams $PoliCheckAdditionalRunConfigParams
115+
116+ # Configure Artifact and Source tools with default Target directories.
117+ Configure- ToolsList $ArtifactToolsList $ArtifactsDirectory
118+ Configure- ToolsList $SourceToolsList $SourceDirectory
119+ # Configure custom tools with no default Target directory.
120+ Configure- ToolsList $CustomToolsList $null
121+
122+ # At this point, all tools are configured in the ".gdn" directory. Run them all in a single call.
123+ # (If we used "run" multiple times, each run would overwrite data from earlier runs.)
124+ Exec- BlockVerbosely {
125+ & $ (Join-Path $PSScriptRoot ' run-sdl.ps1' ) `
126+ - GuardianCliLocation $guardianCliLocation `
127+ - WorkingDirectory $workingDirectory `
128+ - UpdateBaseline $UpdateBaseline `
129+ - GdnFolder $gdnFolder
88130 }
89131
90132 if ($TsaPublish ) {
91133 if ($TsaBranchName -and $BuildNumber ) {
92134 if (-not $TsaRepositoryName ) {
93135 $TsaRepositoryName = " $ ( $Repository ) -$ ( $BranchName ) "
94136 }
95- Write-Host " $guardianCliLocation tsa-publish --all-tools --repository-name `" $TsaRepositoryName `" --branch-name `" $TsaBranchName `" --build-number `" $BuildNumber `" --codebase-name `" $TsaCodebaseName `" --notification-alias `" $TsaNotificationEmail `" --codebase-admin `" $TsaCodebaseAdmin `" --instance-url `" $TsaInstanceUrl `" --project-name `" $TsaProjectName `" --area-path `" $TsaBugAreaPath `" --iteration-path `" $TsaIterationPath `" --working-directory $workingDirectory --logger-level $GuardianLoggerLevel "
96- & $guardianCliLocation tsa- publish -- all- tools -- repository- name " $TsaRepositoryName " -- branch- name " $TsaBranchName " -- build-number " $BuildNumber " -- onboard $True -- codebase- name " $TsaCodebaseName " -- notification- alias " $TsaNotificationEmail " -- codebase- admin " $TsaCodebaseAdmin " -- instance- url " $TsaInstanceUrl " -- project- name " $TsaProjectName " -- area- path " $TsaBugAreaPath " -- iteration- path " $TsaIterationPath " -- working- directory $workingDirectory -- logger- level $GuardianLoggerLevel
137+ Exec- BlockVerbosely {
138+ & $guardianCliLocation tsa- publish -- all- tools -- repository- name " $TsaRepositoryName " -- branch- name " $TsaBranchName " -- build-number " $BuildNumber " -- onboard $True -- codebase- name " $TsaCodebaseName " -- notification- alias " $TsaNotificationEmail " -- codebase- admin " $TsaCodebaseAdmin " -- instance- url " $TsaInstanceUrl " -- project- name " $TsaProjectName " -- area- path " $TsaBugAreaPath " -- iteration- path " $TsaIterationPath " -- working- directory $workingDirectory -- logger- level $GuardianLoggerLevel
139+ }
97140 if ($LASTEXITCODE -ne 0 ) {
98141 Write-PipelineTelemetryError - Force - Category ' Sdl' - Message " Guardian tsa-publish failed with exit code $LASTEXITCODE ."
99142 ExitWithExitCode $LASTEXITCODE
@@ -106,7 +149,11 @@ try {
106149
107150 if ($BreakOnFailure ) {
108151 Write-Host " Failing the build in case of breaking results..."
109- & $guardianCliLocation break
152+ Exec- BlockVerbosely {
153+ & $guardianCliLocation break -- working- directory $workingDirectory -- logger- level $GuardianLoggerLevel
154+ }
155+ } else {
156+ Write-Host " Letting the build pass even if there were breaking results..."
110157 }
111158}
112159catch {
0 commit comments