Simulate a break in the build - nikkh/maug3010 GitHub Wiki
If there is a problem with the build process, we want to fail the build (and also prevent Azure DevOps from moving to the release pipeline. In order to see this in action we'll configure the build to create a work item of type bug when it fails, then we'll amend the unit test code to force a unit test failure and examine the behaviour. Finally we'll fix the bug and allow the solution to be deployed again.
First navigate to your pipeline, then click Edit at the top right of the screen:
One the next screen, select the options tab above the list of build steps:
Select the option to create a work item on build failure. For work item type - choose bug. Save the pipeline (but don't queue)
Next select Repos in the left-navigation menu. Then browse to Project/Application/aspnet-core-dotnet-core.UnitTests/SampleUnitTests.cs. Click edit, then replace the line:
Assert.AreEqual("Index", actual: model.DoTest());
with
Assert.AreNotEqual("Index", actual: model.DoTest());
Then click commit. Accept the default values on the confirm commit dialog that is displayed. This commit will kick off a build. Navigate to your pipeline and you will see the build in progress:
After a while (mine took 1m 35s), your build should fail.
Click on the line where the failure occurred:
Close that window and click on the tests tab. You can see a summary of tests, and for those that failed you can drill-down to the detailed reasons why.:
Navigate to Work Items in the left navigation menu. You will be able to see a work item of type 'bug' that was created automatically when the build failed.
Now it's time to fix our bug. Navigate back to repos and find the file we changed before. Browse to Project/Application/aspnet-core-dotnet-core.UnitTests/SampleUnitTests.cs. Click edit, then replace the line:
Assert.AreNotEqual("Index", actual: model.DoTest());
with
Assert.AreEqual("Index", actual: model.DoTest());
Click commit. The commit confirmation dialog is displayed:
You can select the work item that your change addresses in the 'work items to link' dropdown. We will fix the bug raised when we deliberately broke the build. Click commit. This kicks off another build.
Navigate to pipelines, builds and examine the newly create build that should now be running (you may catch a glimpse of it in the queued state, but it should run shortly).
Click on the build and watch its progress. When its finished click on the summary.