Could you please help with some idea on how to create work-item on azure-boards during the execution of devops build pipeline YAML (it does allure report generation)
I have the following python script to catch the failed test case details from json files generated from Allure-results. After that, I am not able to proceed with any further logic.
Could you help with any REST API or standalone method which I can use in the YAML pipeline itself as the subsequent step/task followed by the python script.
- task: PythonScript@0
inputs:
scriptSource: 'inline'
script: |
import json
import glob
src = "allure-results/"
files = glob.glob('allure-results/*.json', recursive=True)
for single_file in files:
with open(single_file,'r') as f:
print(single_file)
# Use 'try-except' to skip files that may be missing data
try:
json_file = json.load(f)
if json_file['status'] != 'passed':
tsName = json_file['name']
tsStatus = json_file['status']
tsErrMsg = json_file['statusDetails']['message']
tsTrace = json_file['statusDetails']['trace']
tsSeverity = json_file['labels'][0]['name']
tsSevType = json_file['labels'][0]['value']
# print(tsName,"\n",tsStatus,"\n",tsErrMsg,"\n",tsTrace,"\n",tsSeverity,"\n",tsSevType,"\n")
data = [tsName, tsStatus, tsErrMsg, tsTrace, tsSeverity, tsSevType]
print(*data, sep = "\n")
except KeyError:
pass
# print(f'Skipping {single_file}')
workingDirectory: '$(Agent.BuildDirectory)'
I have an idea on how to create the work-item on pipeline failure but want to know how I can create work-item on each testcase failed data stored in python list from the above script.
Just FYI.. I use the below code is for creating work-item on pipeline failure.
- bash: |
az boards work-item create \
--title "Build $(build.buildNumber) failed" \
--type issue \
--org $(System.TeamFoundationCollectionUri) \
--project $(System.TeamProject)
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
displayName: 'Create work item on failure'