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:

Edit build pipeline

One the next screen, select the options tab above the list of build steps:

Edit build pipeline options 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());

Edit Unit Tests

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:

build in progress

After a while (mine took 1m 35s), your build should fail.

build failed

Click on the line where the failure occurred:

build failed detail

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.:

build failed detail

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.

build failed detail

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());

build failed detail

Click commit. The commit confirmation dialog is displayed:

commit confirmation dialog

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).

builds list

Click on the build and watch its progress. When its finished click on the summary.

error fixed

home