Task 9: Initialize the main branch (if it doesn’t exist) and create a pull request-triggered pipeline for .NET Core build
Step 1: Initialize the main Branch
In your Azure DevOps Project (Project1), navigate to Repos.
In the left menu, click Files.
If you see a message like “This repository is empty,” click Initialize.
Create a README.md file (or another file) and set the default branch name to main.
Click Initialize.
If the main branch already exists, you can skip this step.
Step 2: Create a New Branch for the Pipeline
In Repos > Files, click on the Branches tab.
Click New branch.
Enter:
Click Create.
This creates a new branch named azure-pipelinesT from main.
Step 3: Create the Pipeline YAML File in the New Branch
Switch to the azure-pipelinesT branch.
In Files, click New file.
Name the file: azure-pipelines.yml.
Step 4: Write the YAML Pipeline for .NET Core Build
Here’s a sample YAML file:
trigger: none
pr:
branches:
include:
- main
pool:
vmImage: 'windows-latest'
variables:
buildConfiguration: 'Release'
steps:
- task: UseDotNet@2
displayName: 'Install .NET Core SDK'
inputs:
packageType: 'sdk'
version: '8.x' # Or specify the exact version of .NET Core SDK you need
installationPath: $(Agent.ToolsDirectory)/dotnet
- script: dotnet build src --configuration $(buildConfiguration)
displayName: 'Build .NET Core project'
This pipeline:
Runs only when a pull request is created or updated targeting the main branch.
Uses the windows-latest agent.
Installs the .NET SDK and builds the project in the src directory.
Step 5: Commit the Pipeline File
In the bottom commit message box:
Message: Add PR-triggered pipeline for .NET Core build
Ensure the branch is set to azure-pipelinesT.
Click Commit.
Step 6: Create the Pipeline in Azure DevOps
In the left menu, click Pipelines.
Click New pipeline.
Select:
Azure Repos Git.
Select your repository.
Choose Existing Azure Pipelines YAML file.
In the branch selector, choose the azure-pipelinesT branch.
Select the YAML file path (azure-pipelines.yml).
Click Continue and Run to validate.
Step 7: Test the Pipeline Trigger
Create a new branch (e.g., feature/test-pr).
Push a commit and create a pull request targeting main.
Verify that the pipeline runs automatically for this PR in Pipelines.