How to combine two checks with an ‘OR’#
Introduction#
This guide describes, how you can realize more complex condition checks, that require connecting multiple conditions with an OR
instead of the default AND
. For this example, we’re reusing the use case from Getting started with Azure DevOps autopilot, extending it with a second requirement. So the use case looks like the following:
Unclosed, epic work items with a priority of 1 or 2 must:
not be overdue
not be unassigned
to return a GREEN
status.
In case of a priority of 3 or 4, they only must:
not be unassigned
to return a GREEN
status.
You could try to tackle this problem by fetching all unclosed, epic work items and then define a check that follows a logic similar to that:
(Priority == 1 || Priority == 2) && !isUnassigned && !isOverdue || (Priority == 3 || Priority == 4) && !isUnassigned
However, this is not possible since within one fetcher/evaluator config file, you’re only able to pair different conditions with an AND
.
So if you want to do something like in our use case, we need to split up the statement to get rid of the OR
part. Subsequently, we can create a distinct autopilot for each of the two requirements, each of them processing a distinct config file:
The first one will fetch and check the items with priorities 1 & 2 and
the second autopilot fetches and checks the items with priorities 3 & 4.
Both autopilots will then create a report that can be added as evidence to the same question. Now, the overall result of the question will be GREEN
in case both of the generated reports are GREEN
. If one or both of the two reports are RED
, the overall question will also have a RED
status.
Adjusting the config files#
Let’s start with setting up the two fetcher/evaluator config files before we adjust the qg-config.
The first ado config#
workItems:
query: "SELECT [System.Id], [System.State] FROM WorkItems WHERE [System.TeamProject] = @project AND [System.WorkItemType] = 'Epic' AND ([System.State] = 'To Do' OR [System.State] = 'Doing') AND ([Microsoft.VSTS.Common.Priority] = 1 OR [Microsoft.VSTS.Common.Priority] = 2)"
neededFields:
- "assignedTo"
- "targetDate"
evaluate:
settings:
dueDateFieldName: "targetDate"
closedStates:
- "Closed"
- "Done"
checks:
dataExists: true
fields:
dueDate: #To check, whether the DueDate is non existent/overdue
fieldName: "targetDate"
conditions:
resolved:
- ""
assignedTo: #To check, whether the ticket is unassigned or not
fieldName: "assignedTo"
conditions:
illegal:
- ""
Here you can find the config file, corresponding to the first requirement. The fetcher downloads all unfinished, epic work items with a priority of 1 or 2 and the evaluator verifies that they are not overdue and not unassigned.
The second ado config#
workItems:
query: "SELECT [System.Id], [System.State] FROM WorkItems WHERE [System.TeamProject] = @project AND [System.WorkItemType] = 'Epic' AND ([System.State] = 'To Do' OR [System.State] = 'Doing') AND ([Microsoft.VSTS.Common.Priority] = 3 OR [Microsoft.VSTS.Common.Priority] = 4)"
neededFields:
- "assignedTo"
evaluate:
settings:
closedStates:
- "Closed"
- "Done"
checks:
dataExists: true
fields:
assignedTo: #To check, whether the ticket is unassigned or not
fieldName: "assignedTo"
conditions:
illegal:
- ""
Here you can find the config file, corresponding to the second requirement. The fetcher downloads all unfinished, epic work items with a priority of 3 or 4 and the evaluator verifies that they are not unassigned.
The qg-config.yaml#
In order to utilize both of those two config files now, you can just parameterize the autopilot in a second check:
1metadata:
2 version: v1
3header:
4 name: MACMA
5 version: 1.16.0
6env:
7 ADO_API_ORG: team-neutrinos #TODO: change this to your Azure DevOps organization
8 ADO_API_PROJECT: playground #TODO: change this to your Azure DevOps project
9 ADO_APPLY_PROXY_SETTINGS: false
10autopilots:
11 ado-work-items-autopilot:
12 run: |
13 ado-work-items-fetcher
14 ado-work-items-evaluator
15 env:
16 ADO_API_PERSONAL_ACCESS_TOKEN: ${{ secrets.ADO_API_PERSONAL_ACCESS_TOKEN }} # TODO: Add this to your namespace secrets
17finalize:
18 run: |
19 html-finalizer
20chapters:
21 "1":
22 title: Requirements management
23 requirements:
24 "1.1":
25 title: Question to be answered using tickets
26 text: Some sample text, stating what this question is about exactly.
27 checks:
28 1:
29 title: Fetch open, epic work items from ado and ensure they're neither overdue, nor unassigned for priority 1 & 2 and not unassigned for priority 3 & 4.--0
30 automation:
31 autopilot: ado-work-items-autopilot
32 env:
33 ADO_CONFIG_FILE_PATH: ./ado-fetcher-evaluator-config-1.yaml
34 ADO_WORK_ITEMS_JSON_NAME: workItems1.json
35 2:
36 title: Fetch open, epic work items from ado and ensure they're neither overdue, nor unassigned for priority 1 & 2 and not unassigned for priority 3 & 4.--1
37 automation:
38 autopilot: ado-work-items-autopilot
39 env:
40 ADO_CONFIG_FILE_PATH: ./ado-fetcher-evaluator-config-2.yaml
41 ADO_WORK_ITEMS_JSON_NAME: workItems2.json
The proper filenames need to be entered so that the two autopilots actually use the right configs (lines 33, 40) and access the proper files that the fetcher creates (lines 34 and 41).
Resources#
Find the full file, containing the code snippets here: