@@ -136,9 +136,26 @@ stages:
136136 artifactPath : $(Build.ArtifactStagingDirectory)
137137
138138 - pwsh : |
139- $branchName = 'autorest-failed-build-$(Build.BuildId)'
140- $repositoryName = '$(repositories.self.name)'
139+ $sourceBranch = '$(Build.SourceBranch)'
140+ $buildReason = '$(Build.Reason)'
141+ $buildNumber = '$(Build.BuildNumber)'
142+
143+ if ($buildReason -eq 'Schedule') {
144+ $branchName = 'auto-update-autorest-scheduled'
145+ } elseif ($sourceBranch -match "^refs/pull/(\d+)/(head|merge)$") {
146+ $branchName = "auto-update-autorest-pr-$($Matches[1])"
147+ } else {
148+ $branchName = "auto-update-autorest-$buildNumber"
149+ }
150+
151+ Write-Host "Setting variable 'branchName' to '$branchName'"
152+ Write-Host "##vso[task.setvariable variable=branchName;isOutput=true]$branchName"
153+ displayName: Set branch name
154+ name: set_branch_name
141155
156+ - pwsh : |
157+ $repositoryName = '$(repositories.self.name)'
158+ $branchName = '$(set_branch_name.branchName)'
142159 . $(toolsRepositoryPath)/eng/common/scripts/git-branch-push.ps1 `
143160 -PRBranchName $branchName `
144161 -CommitMsg 'Update repo on failing build`n`nBuild url: $(System.CollectionUri)_build/results?buildId=$(Build.BuildId)' `
@@ -293,10 +310,7 @@ stages:
293310 sdkRepositoryCommitSha : $[stageDependencies.Build.Build.outputs['repositories.sdk-repository.version']]
294311 buildArtifactsPath : $(Pipeline.Workspace)/build_artifacts
295312 publishArtifactsPath : $(Pipeline.Workspace)/publish_artifacts
296- ${{ if eq(variables['Build.Reason'], 'Schedule') }} :
297- branchName : auto-update-autorest-scheduled
298- ${{ else }} :
299- branchName : auto-update-autorest-$(Build.BuildNumber)
313+ branchName : $[stageDependencies.Build.Build.outputs['set_branch_name.branchName']]
300314 jobs :
301315 - job : Initialize
302316 steps :
@@ -421,21 +435,26 @@ stages:
421435 - pwsh : |
422436 $generateJobResult = '$(generateJobResult)'
423437 $generatorVersion = '$(generatorVersion)'
438+ $collectionUri = '$(System.CollectionUri)'
439+ $project = '$(System.TeamProject)'
440+ $definitionName = '$(Build.DefinitionName)'
424441 $repoUrl = '$(Build.Repository.Uri)'
425442 $sourceBranch = '$(Build.SourceBranch)'
426- $buildNumber = '$(Build.SourceBranch)'
427- $queuedBy = '$(Build.SourceBranch)'
428443 $reason = '$(Build.Reason)'
444+ $buildId = '$(Build.BuildId)'
445+ $buildNumber = '$(Build.BuildNumber)'
429446 $preRelease = '${{ parameters.BuildPrereleaseVersion }}' -eq 'true'
447+
448+ $prBody = "Generated by $definitionName build [$buildNumber]($collectionUri/$project/_build/results?buildId=$buildId)<br/>"
430449
431450 if ($sourceBranch -match "^refs/heads/(.+)$") {
432- $prBody = "Triggered from branch: [$($Matches[1])]($repoUrl/tree/$sourceBranch)"
451+ $prBody + = "Triggered from branch: [$($Matches[1])]($repoUrl/tree/$sourceBranch)"
433452 } elseif ($sourceBranch -match "^refs/tags/(.+)$") {
434- $prBody = "Triggered from tag: [$($Matches[1])]($repoUrl/tree/$sourceBranch)"
453+ $prBody + = "Triggered from tag: [$($Matches[1])]($repoUrl/tree/$sourceBranch)"
435454 } elseif ($sourceBranch -match "^refs/pull/(\d+)/(head|merge)$") {
436- $prBody = "Triggered from pull request: $repoUrl/pull/$($Matches[1])"
455+ $prBody + = "Triggered from pull request: $repoUrl/pull/$($Matches[1])"
437456 } else {
438- $prBody = "Triggered from [$sourceBranch]($repoUrl/tree/$sourceBranch)"
457+ $prBody + = "Triggered from [$sourceBranch]($repoUrl/tree/$sourceBranch)"
439458 }
440459
441460 if ($reason -eq 'Schedule') {
0 commit comments