Automatically runs a Docker container in Azure Container Instances (ACI) when triggered by Azure DevOps pull request webhooks.
- 🚀 Automatic container execution on PR creation
- 🔒 Managed Identity authentication
- 🧹 Automated cleanup of completed containers
- 🔄 Full integration with Azure DevOps
- Azure account with contributor permissions
- Azure Resource Group with contributor permission
- Azure Container Registry (ACR) with pullRole permission
- Azure Function App
- Docker image pushed to ACR
- Azure DevOps project with admin access
- Azure Portal > Resource Groups > Create
-
azure login
-
az group create --name <RESOURCE_GROUP_NAME> --location <REGION>
- Azure Portal > Container Registries > Create
az acr create --resource-group <RESOURCE_GROUP_NAME> --name <ACR_NAME> --sku Basic- Clone this repository
git clone https://github.com/99x-incubator/azure_pr_review_agent- Navigate to the folder
cd azure_pr_review_agent- Open a command prompt and build the Docker Image
docker build -t azure-pr-agent .- Login to azure
az login- Login to the container registry
az acr login --name <ACR_NAME>- Tag the built image
docker tag azure-pr-agent <ACR_NAME>.azurecr.io/azure-pr-agent:latest- Push the image to the container registry
docker push <ACR_NAME>.azurecr.io/azure-pr-agent:latest- Use .NET runtime stack
![]() |
az functionapp create --resource-group <RESOURCE_GROUP_NAME> --consumption-plan-location <REGION> --runtime dotnet-isolated --functions-version 4 --name <APP_NAME> --storage-account <STORAGE_NAME>4. Configure Permissions(Either you must be an owner of the Azure account you are using, or you must contact an owner of that account and follow these steps)
- Go to the function app
# Get Function App's Managed Identity principal ID
az functionapp identity show --name <your-function-app-name> --resource-group <your-resource-group> --query principalId -o tsv# Assign Contributor role to Managed Identity (replace with your actual subscription and RG)
az role assignment create --assignee <PRINCIPAL_ID(FROM_ABOVE_COMMAND)> --role "Contributor" --scope "/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP_NAME>"![]() |
az role assignment create --assignee <PRINCIPAL_ID(FROM_PREVIOUS_COMMAND> --role AcrPull --scope /subscriptions/<SUB_ID>/resourceGroups/<RESOURCE_GROUP_NAME>/providers/Microsoft.ContainerRegistry/registries/<ACR_NAME>![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Change AZURE_OPENAI_KEY to AZURE_OPENAI_API_KEY in environmental variables
-
-
You can find the ACR_NAME, ACR_PASSWORD, ACR_USERNAME as follows
-
-
(Make sure that you have enabled admin user for the container registry)
-
- Start by cloning the repository to your local machine:
git clone https://github.com/99x-incubator/azure_pr_review_agent_azure_func_net.git
cd azure_pr_review_agent_azure_func_net-
- Open the Project: Open the cloned repository in VS Code.
- Sign in to Azure: Make sure you are signed in to your Azure account using the Azure: Sign In command.
- Deploy the Function App: Press
Ctrl+Shift+Pto open the Command Palette. - Type and select Azure Functions: Deploy to Function App.
- Choose your target Function App from the list.
- Confirm the deployment when prompted and wait for the process to complete.
-
- Alternatively, you can deploy the function using the Azure Functions Core Tools:
- Ensure prerequisites are met: Make sure you have Azure Functions Core Tools installed and you are logged in via the Azure CLI.
- Deploy using the CLI:
# Log in to Azure if you haven't already az login# Publish your function to the specified Function App func azure functionapp publish <FUNCTION_APP_NAME>
- After deployment, the functions should appear in the function app as follows in the portal
-
Note that the container cleanup function runs every 6 hours to remove container instances that are on the terminated, failed or successful state
- Go to Project Settings > Service Hooks
- Create new webhook with:
- Trigger: Pull request created
- URL:
- Using VSCode:
ctrl+shift+P-> Azure Functions: Copy Function URL - Using CLI: Replace "==" in the end of the URL with "%3D%3D" after copying it before pasting in the webhook (This is happening because URL encoding)
FOR /F "delims=" %a IN ('az functionapp function show --resource-group <RESOURCE_GROUP> --name <FUNCTION_APP> --function-name PRReviewTrigger --query invokeUrlTemplate -o tsv') DO SET "URL=%a" FOR /F "delims=" %b IN ('az functionapp function keys list --resource-group <RESOURCE_GROUP> --name <FUNCTION_APP> --function-name PRReviewTrigger --query default -o tsv') DO SET "KEY=%b" ECHO %URL%?code=%KEY%
- Using VSCode:
The container cleanup function will also be deployed to the function app at the deployement of the function mentioned before. This container cleanup function is a time trigger function and it'll delete the container instances that are being teminated, succeeded or failed.








