0

I have a scenarios when i need to create a new branch pull request in Repo A from the chnages done in Repo B using the CD pipeline

Raghu Hoskote
  • 117
  • 2
  • 14

1 Answers1

2

I'm pretty sure there is no set way how to do it from a CI/CD pipeline (please correct me if I'm wrong), but it's definitely doable if you are ready to put together a custom solution.

In this case, I would suggest something similar to this workflow:

  • First of all, set up a pipeline that is triggered when changes are committed to Repository B.

  • After the pipeline checkout is done, create a script that removes remote URLs for Repository B and adds URLs for Repository A. That would look something like this:

     - script: |
         git remote rm origin
         git remote add origin $(your_repo_url)
    
  • Then install the ssh key that allows you to access Repository A. You can use the Install SSH key task YAML template.

  • Create a script that commits and pushes the branch you previously checked out on Repository B to Repository A (in a similar way as the previous script).

  • Finally, use your git repository hosting service API to create a pull request.

LJ.
  • 620
  • 6
  • 12
  • 3
    Instead of using API you can use this task [CreatePullRequest](https://marketplace.visualstudio.com/items?itemName=ShaykiAbramczyk.CreatePullRequest) – Krzysztof Madej Sep 04 '20 at 11:33
  • Yes, that would work as well, thanks! Didn't know about this task. – LJ. Sep 04 '20 at 11:37
  • All credits goes to @shayki-abramczyk [profile](https://stackoverflow.com/users/7409220/shayki-abramczyk) – Krzysztof Madej Sep 04 '20 at 11:45
  • @Krzysztof Madej Thanks for the response. I did check on the [CreatePullRequest](https://marketplace.visualstudio.com/items?itemName=ShaykiAbramczyk) task, but it doesn't not create a pull request from one repo to another repo and at the same time create a new branch. What it does is, it creates a pull request from one existing branch to another existing branch and within the same repo. plz correct me if I am wrong, really appreciate you response guys. – Raghu Hoskote Sep 05 '20 at 17:04
  • @LJ, thanks for the response, will try to implement the same and see how it works out. – Raghu Hoskote Sep 05 '20 at 17:05
  • I think he meant to use `CreatePullRequest` task as an alternative to the 5th bullet point in the workflow I offered as a solution. Instead of using your git repository hosting service API to create pull request, use `CreatePullRequest` task. – LJ. Sep 05 '20 at 17:21
  • @LJ okay got it, thanks for the clarification :) – Raghu Hoskote Sep 05 '20 at 17:41