Rohan Deshmukh
3 min readJun 4, 2024

Azure DevOps: Creating Repositories, Branches and Committing Files with Mulesoft.

In today’s fast-paced development environments, automation is key to maintaining efficiency and consistency. MuleSoft, a robust integration platform, enables seamless connectivity between different systems, including cloud services like Azure.

This blog post will guide you through using MuleSoft to automate the creation of an Azure repository and a new branch within it.

Prerequisites:

Before we begin, ensure you have the following:

  1. An Azure DevOps account.
  2. A MuleSoft Anypoint Platform account.
  3. Basic knowledge of MuleSoft’s Anypoint Studio.

Step-by-Step Guide1.

  1. Set Up Azure DevOps Service Connection

First, you need to create a Personal Access Token (PAT) in Azure DevOps:

  1. Navigate to your Azure DevOps organization.

Signup if you don’t have an account and create a new project.

https://azure.microsoft.com/en-us/products/devops/repos

2. Go to User Settings > Personal Access Tokens.

3. Click + New Token, set the required scopes (e.g., Code (Read & Write)), and generate the token.

2. Configure MuleSoft Anypoint Studio

  1. Open Anypoint Studio and create a new Mule Project.
  2. Add the HTTP Listener connector to trigger the flow.

3. Create Azure Repository

Refer this link for API documentation.

  1. Drag an HTTP Request component to the canvas.
  2. Configure the HTTP Request to call the Azure DevOps REST API for creating a repository. Set the method to POST and the URL to:
https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=6.0

In the Authorization section, Select Basic Authentication:
Username: {Token Name}
Password: {Token Password}

Add the JSON payload to create the repository:

{
"name": "NewRepo",
"project": {
"id": "**/unique id/**"
}
}

Response: Capture -> payload.id store it in variable “id”.

Use get List endpoint to get the project id and list of the repositories.

Use method GET with Basic Auth.

https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=7.1-preview.1

4. Create a New Branch

After the repository creation step, add another HTTP Request component. Use a for each for creation of multiple branches. Commit the read.md or .gitignore file as per need.

Configure this HTTP Request to call the Azure DevOps REST API for creating a new branch. Set the method to POST and the URL to:

https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pushes?api-version=5.1

In the Headers section, reuse the previous headers configuration.

In the body, add the JSON payload before for each to create the branch:

%dw 2.0
output application/json
---
[{
"refUpdates": [
{
"name": "refs/heads/master",
"oldObjectId": "0000000000000000000000000000000000000000"
}
],
"commits": [
{
"comment": "Initial commit.",
"changes": [
{
"changeType": "add",
"item": {
"path": "/readme.md"
},
"newContent": {
"content": "Hello!",
"contentType": "rawtext"
}
}
]
}
]
},
{
"refUpdates": [
{
"name": "refs/heads/qa",
"oldObjectId": "0000000000000000000000000000000000000000"
}
],
"commits": [
{
"comment": "Initial commit.",
"changes": [
{
"changeType": "add",
"item": {
"path": "/readme.md"
},
"newContent": {
"content": "Hello!!,
"contentType": "rawtext"
}
}
]
}
]
},
{
"refUpdates": [
{
"name": "refs/heads/dev",
"oldObjectId": "0000000000000000000000000000000000000000"
}
],
"commits": [
{
"comment": "Initial commit.",
"changes": [
{
"changeType": "add",
"item": {
"path": "/readme.md"
},
"newContent": {
"content": "Hello",
"contentType": "rawtext"
}
}
]
}
]
}
]

5. Test the FlowDeploy your Mule application.Use a tool like Postman to send a request to your Mule application’s HTTP Listener endpoint.

6. Verify that the files, Azure repository and branch are created in your Azure DevOps project.

Conclusion:

By leveraging MuleSoft’s integration capabilities, you can automate the creation of Azure repositories and branches.