From 5f8ae3eacf63348fb4f002319931c2807d2a3604 Mon Sep 17 00:00:00 2001
From: Matthew Leibowitz <mattleibow@live.com>
Date: Thu, 3 Mar 2022 20:24:01 +0800
Subject: [PATCH] Fix the variables of the new pipeline

---
 scripts/azure-templates-stages.yml    |  1 -
 scripts/azure-templates-variables.yml | 21 ++++++++++-----------
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/scripts/azure-templates-stages.yml b/scripts/azure-templates-stages.yml
index 2b16cc2c48..aa9a41d882 100644
--- a/scripts/azure-templates-stages.yml
+++ b/scripts/azure-templates-stages.yml
@@ -17,7 +17,6 @@ stages:
           - template: azure-templates-variables.yml
             parameters:
               updateBuild: true
-          - pwsh: 'dir env:'
           - template: azure-templates-github-status.yml
             parameters:
               context: 'SkiaSharp-Tests'
diff --git a/scripts/azure-templates-variables.yml b/scripts/azure-templates-variables.yml
index 0bec2f95a4..9a53bce84b 100644
--- a/scripts/azure-templates-variables.yml
+++ b/scripts/azure-templates-variables.yml
@@ -15,7 +15,7 @@ steps:
     displayName: Determine the feature name, if any
 
   - pwsh: |
-      $isPR = [regex]::Match("$:env:BUILD_SOURCEBRANCH", 'refs\/pull\/(\d+)\/merge')
+      $isPR = [regex]::Match("$env:BUILD_SOURCEBRANCH", 'refs\/pull\/(\d+)\/merge')
       if ($isPR) {
         if (-not $env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER) {
           $pr = $isPR.Groups[1].Value
@@ -50,16 +50,15 @@ steps:
     condition: eq(variables['Build.Reason'], 'Schedule')
 
   - pwsh: |
-      if ($env:RESOURCES_PIPELINE_SKIASHARP_RUNNAME) {
-        Write-Host "Working with $env:RESOURCES_PIPELINE_SKIASHARP_RUNNAME"
-        $match = [regex]::Match("$env:RESOURCES_PIPELINE_SKIASHARP_RUNNAME", '.*\-(.+)\.(\d+)')
-        $label = $match.Groups[1].Value
-        Write-Host "Preview label: $label"
-        Write-Host "##vso[task.setvariable variable=PREVIEW_LABEL]$label"
-        $buildnumber = $match.Groups[2].Value
-        Write-Host "Build number: $buildnumber"
-        Write-Host "##vso[task.setvariable variable=BUILD_NUMBER]$buildnumber"
-      }
+      Write-Host "Working with $env:RESOURCES_PIPELINE_SKIASHARP_RUNNAME"
+      $match = [regex]::Match("$env:RESOURCES_PIPELINE_SKIASHARP_RUNNAME", '.*\-(.+)\.(\d+)')
+      $label = $match.Groups[1].Value
+      Write-Host "Preview label: $label"
+      Write-Host "##vso[task.setvariable variable=PREVIEW_LABEL]$label"
+      $buildnumber = $match.Groups[2].Value
+      Write-Host "Build number: $buildnumber"
+      Write-Host "##vso[task.setvariable variable=BUILD_NUMBER]$buildnumber"
+    condition: eq(variables['Build.Reason'], 'ResourceTrigger')
     displayName: Override the preview label and build number if this is a secondary build
 
   - pwsh: |