diff --git a/eng/common/pipelines/templates/steps/set-default-branch.yml b/eng/common/pipelines/templates/steps/set-default-branch.yml new file mode 100644 index 000000000000..77e1d08a48d0 --- /dev/null +++ b/eng/common/pipelines/templates/steps/set-default-branch.yml @@ -0,0 +1,7 @@ +steps: +- pwsh: | + $setDefaultBranch = (git remote show origin | Out-String) -replace "(?ms).*HEAD branch: (\w+).*", '$1' + Write-Host $setDefaultBranch + echo "##vso[task.setvariable variable=DefaultBranch]$setDefaultBranch" + displayName: "Setup Default Branch" + condition: eq(variables['DefaultBranch'], '') \ No newline at end of file diff --git a/eng/common/pipelines/templates/steps/verify-links.yml b/eng/common/pipelines/templates/steps/verify-links.yml index 1990ffe07dba..7cf296d2f96e 100644 --- a/eng/common/pipelines/templates/steps/verify-links.yml +++ b/eng/common/pipelines/templates/steps/verify-links.yml @@ -6,11 +6,12 @@ parameters: Recursive: $false CheckLinkGuidance: $true Urls: '(Get-ChildItem -Path ./ -Recurse -Include *.md)' - BranchReplaceRegex: "^(${env:SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI}.*/(?:blob|tree)/)master(/.*)$" + BranchReplaceRegex: "(^${env:SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI}.*/(?:blob|tree)/)$(DefaultBranch)(/.*)$" BranchReplacementName: "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}" Condition: succeeded() # If you want to run on failure for the link checker, set it to `Condition: succeededOrFailed()`. steps: + - template: /eng/common/pipelines/templates/steps/set-default-branch.yml - task: PowerShell@2 displayName: Link verification check condition: ${{ parameters.Condition }} @@ -26,4 +27,4 @@ steps: -branchReplaceRegex "${{ parameters.BranchReplaceRegex }}" -branchReplacementName ${{ parameters.BranchReplacementName }} -devOpsLogging: $true - -checkLinkGuidance: ${{ parameters.CheckLinkGuidance }} + -checkLinkGuidance: ${{ parameters.CheckLinkGuidance }} \ No newline at end of file diff --git a/eng/common/scripts/Verify-Links.ps1 b/eng/common/scripts/Verify-Links.ps1 index 18aedd447da9..d1dbb085a3a7 100644 --- a/eng/common/scripts/Verify-Links.ps1 +++ b/eng/common/scripts/Verify-Links.ps1 @@ -278,7 +278,8 @@ function GetLinks([System.Uri]$pageUri) return $links; } - +Write-Host "Here is the place to look into default branch." +Write-Host $branchReplaceRegex if ($urls) { if ($urls.Count -eq 0) { Write-Host "Usage $($MyInvocation.MyCommand.Name) "; diff --git a/eng/pipelines/aggregate-reports.yml b/eng/pipelines/aggregate-reports.yml index 8428cc7c0af8..b4a4f775d91d 100644 --- a/eng/pipelines/aggregate-reports.yml +++ b/eng/pipelines/aggregate-reports.yml @@ -103,6 +103,13 @@ jobs: # Only run if building all libraries succeeded. condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) displayName: 'Component Detection' + # Run link verification at the end as it will run no matter the pipeline passing or failing. + # If this task fails with an error it shouldn't prevent aggregate reports from being generated. + - template: ../common/pipelines/templates/steps/verify-links.yml + parameters: + Directory: "" + CheckLinkGuidance: $true + Condition: succeededOrFailed() # Put cred scan step before install and build packages to avoid the tool scans generated folder like /target. - task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@3 @@ -126,10 +133,3 @@ jobs: # GdnBreakOutputBaseline: baseline condition: succeededOrFailed() continueOnError: true - # Run link verification at the end as it will run no matter the pipeline passing or failing. - # If this task fails with an error it shouldn't prevent aggregate reports from being generated. - - template: ../common/pipelines/templates/steps/verify-links.yml - parameters: - Directory: "" - CheckLinkGuidance: $true - Condition: succeededOrFailed() diff --git a/eng/pipelines/templates/jobs/archetype-sdk-client.yml b/eng/pipelines/templates/jobs/archetype-sdk-client.yml index 42452dcf6f90..0eb801909dda 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-client.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-client.yml @@ -201,7 +201,7 @@ jobs: ${{ if ne(variables['Build.Reason'], 'PullRequest') }}: Directory: sdk/${{ parameters.ServiceDirectory }} CheckLinkGuidance: $true - + Condition: succeededOrFailed() # Use BasePathLength of 38 instead of the default 49 as some GA'd files fail when the number is higher. - template: /eng/common/pipelines/templates/steps/verify-path-length.yml parameters: