Skip to content

Conversation

@lpatalas
Copy link
Contributor

Description

Related issue: #7616

This PR solves the same issue as similar PR for 3.x branch: #7654

This PR introduces the change to fail the build step when SDL reports errors. On 5.0 we have the same problem as on 3.x - we are shadowing $LASTEXITCODE variable by calling $LASTEXITCODE = 0 at the beginning of scripts. It should be $global:LASTEXITCODE = 0.

Example build: https://dev.azure.com/dnceng/internal/_build/results?buildId=1255281
Example build that failed because of SDL error: https://dev.azure.com/dnceng/internal/_build/results?buildId=1255232

Customer Impact

Without fixing the error handling we may miss security issues reported by the SDL scanner.

Regression

There can be possible changes in behavior because we were ignoring all errors in SDL step before. Now they will fail the build.

Risk

The biggest risk is that fixing the error handling will make pipelines fail on SDL stage because of errors that we previously silently ignored.

Workarounds

If our target is to fail the build on SDL errors then I believe this the minimal amount of changes we have to make. The alternative is to keep track of the issues manually but this seems impractical in the long term.


if ($ArtifactToolsList -and $ArtifactToolsList.Count -gt 0) {
& $(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
if ($LASTEXITCODE -ne 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these need to be prefixed with $global: too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They don't have to. The main problem is assigning $LASTEXITCODE without using global: prefix because it creates local variable that shadows the global one. We could use $global:LASTEXITCODE everywhere just to be on the safe side but I thought it would be an overkill.

@MattGal MattGal merged commit fd70fce into release/5.0 Jul 23, 2021
@premun premun deleted the lupatala/fix-sdl-5.0 branch July 26, 2021 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants