Reputation: 2304
Is there a way to merge one branch to another using the API?
I had a look here, but it doesn't seem to offer me a solution to what I want (pushing individual files is tedious): https://www.visualstudio.com/en-us/docs/integrate/api/git/pushes
I suppose if there isn't a way to do this using the rest API, can it be done via git commands run through a powershell script on the private build agent?
Upvotes: 3
Views: 1850
Reputation: 529
As a follow up to VonC's solution, you'll need to grant the VSTS Build service account permissions to contribute to the repository.
Note: Read is also required but should already be allowed.
You'll also need to create the build variable: system.prefergit and set that value to true.
These steps are detailed in the link provided by VonC
Upvotes: 1
Reputation: 33738
First, refer to VonC’s solution.
Secondly, you can do it through Pull Request REST API. (Create a pull request during build/release, update pull request status to completed)
Upvotes: 2
Reputation: 1329282
No, there does not seem to be any merge operation exposed in the VSTS Git or Version Control API.
That leaves you with the official "Build and Release step": "Run Git commands in a script", which does enable you to run Git commands, then push back to the VSTS-Git repo.
That page has a script with a merge example (simple bat script though, not a Powershell one):
@echo off
ECHO SOURCE BRANCH IS %BUILD_SOURCEBRANCH%
IF %BUILD_SOURCEBRANCH% == refs/heads/master (
ECHO Building master branch so no merge is needed.
EXIT
)
SET sourceBranch=origin/%BUILD_SOURCEBRANCH:refs/heads/=%
ECHO GIT CHECKOUT MASTER
git checkout master
ECHO GIT STATUS
git status
ECHO GIT MERGE
git merge %sourceBranch% -m "Merge to master"
ECHO GIT STATUS
git status
ECHO GIT PUSH
git push origin
ECHO GIT STATUS
git status
Upvotes: 4