Azure / Azure/azure-cli

az repos pr create --delete-source-branch

Open
#27,498 6 comments 6 reactions 0 assignees View on GitHub
act-platform-engineering-squad Auto-Assign bug customer-reported DevOps Service Attention
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

### Describe the bug

In a CI/CD workflow in Azure Releases, I automatically create a PR after a stage.
When this PR is approved and completed, I want it to be automatically be deleted, and set the flag `--delete-source-branch true`.
[Documentation](https://learn.microsoft.com/en-us/cli/azure/repos/pr?view=azure-cli-latest#az-repos-pr-create(azure-devops)) explains:
`Delete the source branch after the pull request has been completed and merged into the target branch.`

The PR get created successfully, but the branch is not deleted when I complete the PR.

Note that this PR is created as the user Project Collection Build Service ({OrgName}), using the:
environment token in Azure Releases:
`AZURE_DEVOPS_EXT_PAT` and `$(System.AccessToken)`

### Related command

```
az repos pr create \
--project ProjectName \
--organization https://dev.azure.com/Project/ \
--repository RepositoryName \
--delete-source-branch true \
--source-branch $BRANCH_NAME \
--target-branch main \
--title "Title $BUILDID, release $RELEASENAME, $(date +%Y%m%d%H%M)" \
--reviewers "areviewer@foo.com"
--description "Deployed $(date -I)" "ref: $BUILD_COMMIT"
```

### Errors

no errors

### Issue script & Debug output

cli.knack.cli: Command arguments: ['repos', 'pr', 'create', '--project', 'Project', '--organization', 'https://dev.azure.com/Organization/', '--repository', 'ProjectBackend', '--delete-source-branch', 'true', '--source-branch', 'testing_pr_loc', '--target-branch', 'testing_pr', '--title', 'TESTING', '--reviewers', 'foo@bar.com', '--description', '- Deployed Synapse to prod 2023-09-29', 'testing', '--debug']

### Expected behavior

I expect that the branch will be deleted after the PR has been completed, as documentation says.

### Environment Summary

bash script, running in a `Bash@3 - Bash v3 task`

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.