diff --git a/build/buildpipeline/security/DotNet-CLI-Security-Windows.json b/build/buildpipeline/security/DotNet-CLI-Security-Windows.json index 35bdd379e2..1226921bbf 100644 --- a/build/buildpipeline/security/DotNet-CLI-Security-Windows.json +++ b/build/buildpipeline/security/DotNet-CLI-Security-Windows.json @@ -237,6 +237,28 @@ "failOnStandardError": "true" } }, + { + "environment": {}, + "enabled": true, + "continueOnError": false, + "alwaysRun": false, + "displayName": "Get latest version info", + "timeoutInMinutes": 0, + "condition": "succeeded()", + "refName": "PowerShell23", + "task": { + "id": "e213ff0f-5d5c-4791-802d-52ea3e7be1f1", + "versionSpec": "1.*", + "definitionType": "task" + }, + "inputs": { + "scriptType": "filePath", + "scriptName": "$(Build.SourcesDirectory)\\build\\buildpipeline\\security\\Get-LatestVersion.ps1", + "arguments": "-Branch \"$(CodeBase)\"", + "workingFolder": "$(Build.SourcesDirectory)\\$(PB_Repo)\\build\\buildpipeline\\security\\", + "failOnStandardError": "true" + } + }, { "enabled": true, "continueOnError": true, diff --git a/build/buildpipeline/security/Get-LatestVersion.ps1 b/build/buildpipeline/security/Get-LatestVersion.ps1 index 5e20756f8a..a9d3fdf405 100644 --- a/build/buildpipeline/security/Get-LatestVersion.ps1 +++ b/build/buildpipeline/security/Get-LatestVersion.ps1 @@ -2,7 +2,7 @@ .SYNOPSIS Retrieves the latest commit SHA and the corresponding package Id for the specified branch of CLI. This retrieval is achieved by downloading the latest.version file, which contains the commit SHA and package Id info. - If retrieval succeeds, then the commit is set as $env:CliLatestCommitSha, and package Id is set as $env:CliLatestPackageId. + If retrieval succeeds, then the commit is set as a VSTS Task Variable named CliLatestCommitSha, and similarly package Id is set as CliLatestPackageId. .PARAMETER $Branch Name of the CLI branch. .PARAMETER $Filename @@ -20,12 +20,6 @@ param( [string]$UrlPrefix="https://dotnetcli.blob.core.windows.net/dotnet/Sdk" ) -$latestVersionUrl = "$UrlPrefix/$Branch/$Filename" -$latestVersionFilePath = ".\latest.version" -$env:CliLatestCommitSha = "" -$env:CliLatestPackageId = "" - - function Get-VersionInfo { Write-Host "Attempting to retrieve latest version info from $latestVersionUrl" @@ -39,18 +33,7 @@ function Get-VersionInfo try { - if(Test-Path "$latestVersionFilePath") - { - Remove-Item "$latestVersionFilePath" -Force - } - - Invoke-WebRequest -Uri "$latestVersionUrl" -OutFile "$latestVersionFilePath" - - $latestVersionContent = Get-Content "$latestVersionFilePath" - $env:CliLatestCommitSha = $latestVersionContent[0] - $env:CliLatestPackageId = $latestVersionContent[1] - - break + return (Invoke-WebRequest -Uri "$latestVersionUrl" -UseBasicParsing).Content.Split([Environment]::NewLine, [System.StringSplitOptions]::RemoveEmptyEntries) } catch { @@ -67,15 +50,19 @@ function Get-VersionInfo } } -Get-VersionInfo +$latestVersionUrl = "$UrlPrefix/$Branch/$Filename" +$latestVersionContent = Get-VersionInfo -if (-not [string]::IsNullOrWhiteSpace($env:CliLatestCommitSha) -and -not [string]::IsNullOrWhiteSpace($env:CliLatestPackageId)) +if (-not [string]::IsNullOrWhiteSpace($latestVersionContent) -and $latestVersionContent.Length -eq 2) { - Write-Host "##vso[task.setvariable variable=CliLatestCommitSha;]$env:CliLatestCommitSha" - Write-Host "##vso[task.setvariable variable=CliLatestPackageId;]$env:CliLatestPackageId" + $CliLatestCommitSha = $latestVersionContent[0] + $CliLatestPackageId = $latestVersionContent[1] + + Write-Host "##vso[task.setvariable variable=CliLatestCommitSha;]$CliLatestCommitSha" + Write-Host "##vso[task.setvariable variable=CliLatestPackageId;]$CliLatestPackageId" - Write-Host "The latest commit SHA in CLI $Branch is $env:CliLatestCommitSha" - Write-Host "The latest package Id in CLI $Branch is $env:CliLatestPackageId" + Write-Host "The latest commit SHA in CLI $Branch is $CliLatestCommitSha" + Write-Host "The latest package Id in CLI $Branch is $CliLatestPackageId" } else {