bkqc
bkqc

Reputation: 1021

Azure DevOps Pipelines: How to run only impacted tests only when Reason is Check in without duplicating?

I have a build process in which I have a couple of Tests Tasks. Some of them may become quite time consuming when they all run and most of the time, most tests are not expected.

Still, I would like to have ALL these tests run on a scheduled trigger.

I know I could simply clone the pipeline and use one for gating with impacted tests only and the other one for schedule with all tests but as an OO developer, I don't like this.

I already tried linking the checkbox parameter to a process variable and modifying it using PowerShell but failed to have it work (How can I modify a process variable using Powershell in a Azure build pipeline).

Isn't there any other way of doing this?

Upvotes: 0

Views: 1264

Answers (2)

Matthew Steeples
Matthew Steeples

Reputation: 8058

It looks like functionality for this is now built in. According to the docs a variable can be set which will cause all tests to be run:

By setting a build variable. Even after TIA has been enabled in the VSTest task, it can be disabled for a specific build by setting the variable DisableTestImpactAnalysis to true. This override will force TIA to run all tests for that build. In subsequent builds, TIA will go back to optimized test selection

Upvotes: 1

poltj18
poltj18

Reputation: 286

You may be able to do this by setting the following condition on the test tasks that you'd only like to run during the scheduled build:

eq(variables['Build.Reason'], 'Schedule')

See here for a list of predefined variables (search for 'Build.Reason'):

https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml

See here for more information on expressions:

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops

Upvotes: 1

Related Questions