Untitled

mail@pastecode.io avatar
unknown
plain_text
8 months ago
943 B
1
Indexable
Never
trigger:
  branches:
    include:
      - '*'

pr:
  branches:
    include:
      - '*'

pool:
  vmImage: 'windows-latest'

steps:
- checkout: self

- script: |
    # Ensure you are on the target branch
    git checkout test

    # Merge changes from the source branch
    git merge $(System.PullRequest.SourceBranch)

    # Push changes to the repository
    git push origin test
  displayName: 'Merge changes to test'

- powershell: |
    $sourceBranch = '$(System.PullRequest.SourceBranch)'

    $url = "$(System.CollectionUri)$(System.TeamProject)/_apis/git/repositories/$(Build.Repository.ID)/refs/heads/$($sourceBranch)?api-version=6.0"

    $token = "YOUR_PERSONAL_ACCESS_TOKEN_HERE"
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($token)"))

    Invoke-RestMethod -Uri $url -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method Delete
  displayName: 'Delete source branch after merge'