From f5fb67d04a2f14cd5dede3bff8f3c5922d3211c7 Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Tue, 5 Mar 2024 14:46:30 -0800 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools for PR 7810 (#22526) * Run publish on failed or succeeded * Expand agent os string detection * Check agent job status env var for artifact name detection * Add sbomEnabled flag to publish template * Fix image and artifact name conditional --------- Co-authored-by: Ben Broderick Phillips --- .../templates/jobs/generate-job-matrix.yml | 2 +- .../templates/steps/publish-1es-artifact.yml | 24 ++++++++++--------- eng/common/scripts/Verify-AgentOS.ps1 | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/eng/common/pipelines/templates/jobs/generate-job-matrix.yml b/eng/common/pipelines/templates/jobs/generate-job-matrix.yml index 67ee92a93839..a7459e6b5db5 100644 --- a/eng/common/pipelines/templates/jobs/generate-job-matrix.yml +++ b/eng/common/pipelines/templates/jobs/generate-job-matrix.yml @@ -66,7 +66,7 @@ jobs: value: $[ coalesce(variables.jobMatrixFilter, '.*') ] pool: name: ${{ parameters.Pool }} - vmImage: ${{ parameters.OsVmImage }} + image: ${{ parameters.OsVmImage }} os: ${{ parameters.Os }} ${{ if parameters.DependsOn }}: dependsOn: ${{ parameters.DependsOn }} diff --git a/eng/common/pipelines/templates/steps/publish-1es-artifact.yml b/eng/common/pipelines/templates/steps/publish-1es-artifact.yml index b06b2d0e444c..7648a34165f7 100644 --- a/eng/common/pipelines/templates/steps/publish-1es-artifact.yml +++ b/eng/common/pipelines/templates/steps/publish-1es-artifact.yml @@ -5,26 +5,28 @@ # ArtifactName - The name of the artifact in the "successful" case. # ArtifactPath - The path we will be publishing. # CustomCondition - Used if there is additional logic necessary to prevent attempt of publish. +# SbomEnabled - Set whether to auto-inject 1es pipeline template sbom tasks parameters: ArtifactName: '' ArtifactPath: '' CustomCondition: true + SbomEnabled: true steps: - pwsh: | - Write-Host "##vso[task.setvariable variable=PublishArtifactName;]${{ parameters.ArtifactName }}" - condition: and(succeeded(), ${{ parameters.CustomCondition }}) - displayName: Set Artifact Name - - - pwsh: | - Write-Host "##vso[task.setvariable variable=PublishArtifactName;]${{ parameters.ArtifactName }}-FailedAttempt$(System.JobAttempt)" - condition: and(failed(), ${{ parameters.CustomCondition }}) - displayName: Set Failed Artifact Name + if ($env:AGENT_JOBSTATUS -eq "Failed") { + Write-Host "##vso[task.setvariable variable=PublishArtifactName;]${{ parameters.ArtifactName }}-FailedAttempt$(System.JobAttempt)" + } else { + Write-Host "##vso[task.setvariable variable=PublishArtifactName;]${{ parameters.ArtifactName }}" + } + condition: and(succeededOrFailed(), ${{ parameters.CustomCondition }}) + displayName: Set Artifact Name $(Agent.JobStatus) - task: 1ES.PublishPipelineArtifact@1 - condition: and(succeeded(), ${{ parameters.CustomCondition }}) + condition: and(succeededOrFailed(), ${{ parameters.CustomCondition }}) displayName: 'Publish ${{ parameters.ArtifactName }} Artifacts' inputs: - artifact: '$(PublishArtifactName)' - path: '${{ parameters.ArtifactPath }}' + artifactName: '$(PublishArtifactName)' + targetPath: '${{ parameters.ArtifactPath }}' + sbomEnabled: ${{ parameters.SbomEnabled }} diff --git a/eng/common/scripts/Verify-AgentOS.ps1 b/eng/common/scripts/Verify-AgentOS.ps1 index 3839553a0ff7..e67c5e5aa2b9 100644 --- a/eng/common/scripts/Verify-AgentOS.ps1 +++ b/eng/common/scripts/Verify-AgentOS.ps1 @@ -10,9 +10,9 @@ function Throw-InvalidOperatingSystem { if ($IsWindows -and $AgentImage -match "windows|win|MMS\d{4}") { $osName = "Windows" -} elseif ($IsLinux -and $AgentImage -match "ubuntu") { +} elseif ($IsLinux -and $AgentImage -match "ubuntu|linux") { $osName = "Linux" -} elseif ($IsMacOs -and $AgentImage -match "macos") { +} elseif ($IsMacOs -and $AgentImage -match "macos|macOS") { $osName = "macOS" } else { Throw-InvalidOperatingSystem