Skip to content

Azure Pipelines task to create PR during a build or release

License

Notifications You must be signed in to change notification settings

elliotzh/azure-devops-create-pr-task

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Release Extension
Build Status Release Status Extnesion

Azure DevOps Create Pull Request Task

An easy way to automatically create a Pull Request from your Build or Release Pipeline.

You can create a Pull Request to an Azure DevOps (Repos) repository or to a GitHub repository.

Support multi target branch (PR from one source branch to many target branches) and Draft Pull Request.

Choose title, description, reviewers and more.

Prerequisites

  • The task currently only works on Windows machines.

For Azure DevOps Repository:

  • You need to enable the "Allow scripts to access the OAuth token":

    • If you use the classic editor, go to the Agent job options, scroll down and check the checkbox "Allow scripts to acess the OAuth token":

      Oauth

    • If you use yaml build, you need to map the variable in the task:

       env:
         System_AccessToken: $(System.AccessToken)
  • You need to give permissions to the build user (in Microsoft hosted agnet is "Build Service (user-name)"):

    Permissions

For GitHub Repository:

Usage

In the classic editor:

Task

  • Git repository type: Azure DevOps (Repos) or GitHub. When you choose GitHub you need to choose from the list the GitHub service connection (that use PAT authorization.)

  • GitHub Connection (authorized with PAT): When you choose GitHub in Git repository type you need to specify here the GitHub service connection.

  • Source branch name: The source branch that will be merged. The default value is the build source branch - $(Build.SourceBranch).

  • Target branch name: The target branch name that the source branch will be merge to him. For example: master. Supports also multi target branch with *, for example: test/*.

  • Title: The Pull Request title.

  • Description: The Pull Request description. (Optional).

  • Reviewers: The Pull Request reviewers (Optional) .
    For Azure DevOps - one or more email address or team name separated by semicolon. For example: test@test.com;MyTeamName.
    For GitHub: one or more usernames separated by semicolon. For example: user1;user2.

  • Create Draft Pull Request: If checekd the pull request will be a Draft Pull Request. (Default: false)
    For Azure DevOps: see here more info.
    For GitHub: see here more info.

  • Link Work Items: If checked, all the work items that linked to the commits will be linked also to the PullRequest.

  • Set Auto Complete: Only for Azure DevOps. If checekd the pull request will close once all branch policies are met.

    Complete options:

    • Merge Strateg: Specify the strategy used to merge the pull request during completion, see here more info.
      • Merge (No fast-forward) - noFastForward in yaml:

        A two-parent, no-fast-forward merge. The source branch is unchanged. This is the default behavior.

      • Squash commit - squash in yaml:

        Put all changes from the pull request into a single-parent commit.

      • Rebase and fast-forward - rebase in yaml:

        Rebase the source branch on top of the target branch HEAD commit, and fast-forward the target branch. The source branch is updated during the rebase operation.

      • Rebase and not fast-forward - rebaseMerge in yaml:

        Rebase the source branch on top of the target branch HEAD commit, and create a two-parent, no-fast-forward merge. The source branch is updated during the rebase operation.

    • Delete Sourch Branch: If true, the source branch of the pull request will be deleted after completion.
    • Commit Message: If set, this will be used as the commit message of the merge commit. if empty the default will be used.
    • Complete Associated Work Items: If true, we will attempt to transition any work items linked to the pull request into the next logical state (i.e. Active -> Resolved).

In yaml piepline:

- task: CreatePullRequest@1
  inputs:
    repoType: Azure DevOps / GitHub
    githubEndpoint: 'my-github' # When you choose GitHub in `repoType` you need to specify here the GitHub service connection
    sourceBranch: '$(Build.SourceBranch)'
    targetBranch: 'master'
    title: 'Test'
    description: 'Test' # Optional
    reviewers: For Azure DevOps: 'test@test.com;MyTeam'. For GitHub: `username;username2` # Optional
    isDraft: false / true (Default: false) 
    linkWorkItems: false / true (Default: true)
    autoComplete: false / true (Default: false) 
    mergeStrategy: 'noFastForward (default) / squash / rebase / rebaseMerge'
    deleteSourch:  false / true (Default: false) # Optional
    commitMessage: 'Test Comment' # Optional
    transitionWorkItems:  false / true (Default: false) # Optional
  env:
    System_AccessToken: $(System.AccessToken)

Known issue(s)

  • In Azure DevOps Server (TFS) you can't use reviewers. still can create a PR without it. [Fixed in version 1.2.18]

Release Notes

1.2.48

  • Link associated work items to the PR (for Azure DevOps)

1.2.36

  • Add complete options like Merge Strategy and more in auto completion (for Azure DevOps).

1.2.30

  • Support also a Team as reviewers (for Azure DevOps).

1.2.24

  • Set Auto Complete the Pull Request (for Azure DevOps).

1.2.18

  • Bug fix: Now you can add reviewers also in TFS 2018 and Azure DevOps Server 2019.

1.2.15

  • Draft Pull Request option.

1.2.0

  • Support also GitHub repositories!

1.0.31

  • Multi target branch (For example: feature/*)

1.0.0

  • First version.

About

Azure Pipelines task to create PR during a build or release

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PowerShell 100.0%