From 52bb8157d4c8d0783d98043647507214a0c7663e Mon Sep 17 00:00:00 2001 From: Sima Zhu Date: Wed, 14 Apr 2021 14:48:39 -0700 Subject: [PATCH 1/4] Set default branch to master if not set from git --- eng/common/pipelines/templates/steps/git-push-changes.yml | 2 +- eng/common/pipelines/templates/steps/set-default-branch.yml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/eng/common/pipelines/templates/steps/git-push-changes.yml b/eng/common/pipelines/templates/steps/git-push-changes.yml index a922b203a9..15c8699018 100644 --- a/eng/common/pipelines/templates/steps/git-push-changes.yml +++ b/eng/common/pipelines/templates/steps/git-push-changes.yml @@ -41,7 +41,7 @@ steps: - task: PowerShell@2 displayName: Push changes - condition: and(succeeded(), eq(variables['HasChanges'], 'true')) + condition: and(succeeded(), ne(variables['HasChanges'], 'false')) inputs: pwsh: true workingDirectory: ${{ parameters.WorkingDirectory }} diff --git a/eng/common/pipelines/templates/steps/set-default-branch.yml b/eng/common/pipelines/templates/steps/set-default-branch.yml index b66478975a..199ae6b7cc 100644 --- a/eng/common/pipelines/templates/steps/set-default-branch.yml +++ b/eng/common/pipelines/templates/steps/set-default-branch.yml @@ -4,7 +4,11 @@ parameters: steps: - pwsh: | $setDefaultBranch = (git remote show ${{ parameters.RemoteRepo }} | Out-String) -replace "(?ms).*HEAD branch: (\w+).*", '$1' + if (!$setDefaultBranch) { + $setDefaultBranch = 'master' + } Write-Host "Setting DefaultBranch=$setDefaultBranch" echo "##vso[task.setvariable variable=DefaultBranch]$setDefaultBranch" displayName: "Setup Default Branch" workingDirectory: ${{ parameters.workingDirectory }} + continueOnError: true From 4dc6e25f46997b68a17785ca1d4a9ca5c93a8bfc Mon Sep 17 00:00:00 2001 From: Sima Zhu Date: Wed, 14 Apr 2021 15:00:45 -0700 Subject: [PATCH 2/4] Added log messages --- eng/common/pipelines/templates/steps/set-default-branch.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eng/common/pipelines/templates/steps/set-default-branch.yml b/eng/common/pipelines/templates/steps/set-default-branch.yml index 199ae6b7cc..48bbcb62aa 100644 --- a/eng/common/pipelines/templates/steps/set-default-branch.yml +++ b/eng/common/pipelines/templates/steps/set-default-branch.yml @@ -4,7 +4,8 @@ parameters: steps: - pwsh: | $setDefaultBranch = (git remote show ${{ parameters.RemoteRepo }} | Out-String) -replace "(?ms).*HEAD branch: (\w+).*", '$1' - if (!$setDefaultBranch) { + if ($LASTEXITCODE -ne 0) { + Write-Host "Not able to fetch the default branch from git command. Set to master." $setDefaultBranch = 'master' } Write-Host "Setting DefaultBranch=$setDefaultBranch" From d3a783afe984411e72d19376e3691b772aa54fb5 Mon Sep 17 00:00:00 2001 From: Sima Zhu Date: Thu, 15 Apr 2021 11:59:33 -0700 Subject: [PATCH 3/4] Silent the failure if not able fetch default branch from git --- eng/common/pipelines/templates/steps/set-default-branch.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/common/pipelines/templates/steps/set-default-branch.yml b/eng/common/pipelines/templates/steps/set-default-branch.yml index 48bbcb62aa..e3eed4512d 100644 --- a/eng/common/pipelines/templates/steps/set-default-branch.yml +++ b/eng/common/pipelines/templates/steps/set-default-branch.yml @@ -9,7 +9,7 @@ steps: $setDefaultBranch = 'master' } Write-Host "Setting DefaultBranch=$setDefaultBranch" - echo "##vso[task.setvariable variable=DefaultBranch]$setDefaultBranch" + Write-Host "##vso[task.setvariable variable=DefaultBranch]$setDefaultBranch" displayName: "Setup Default Branch" workingDirectory: ${{ parameters.workingDirectory }} - continueOnError: true + ignoreLASTEXITCODE: true From a27a5100297205d1800ef1f49115bf7e118e72d3 Mon Sep 17 00:00:00 2001 From: Sima Zhu <48036328+sima-zhu@users.noreply.github.com> Date: Mon, 19 Apr 2021 12:09:33 -0700 Subject: [PATCH 4/4] Update git-push-changes.yml --- eng/common/pipelines/templates/steps/git-push-changes.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/pipelines/templates/steps/git-push-changes.yml b/eng/common/pipelines/templates/steps/git-push-changes.yml index 15c8699018..a922b203a9 100644 --- a/eng/common/pipelines/templates/steps/git-push-changes.yml +++ b/eng/common/pipelines/templates/steps/git-push-changes.yml @@ -41,7 +41,7 @@ steps: - task: PowerShell@2 displayName: Push changes - condition: and(succeeded(), ne(variables['HasChanges'], 'false')) + condition: and(succeeded(), eq(variables['HasChanges'], 'true')) inputs: pwsh: true workingDirectory: ${{ parameters.WorkingDirectory }}