Is there a way to create a bug automatically in azure dev-ops when there is a failure in pipeline execution?
Thanks, Sudheer
Your requirement make a sense. The below code should works.
trigger:
- none
pool:
vmImage: ubuntu-latest
steps:
#The previous steps here.
- script: |
echo Add other tasks to build, test, and deploy your project.
# xxx
displayName: 'Run a multi-line script'
- script: |
echo Add other tasks to build, test, and deploy your project.
xxx
displayName: 'Run a multi-line script'
#Additional Steps to create bug workitems.
- task: PythonScript@0
condition: failed()
inputs:
scriptSource: 'inline'
script: |
#create a bug workitem for azure devops
import json
import requests
#give the required information here.
organization = "<Your Organization Name>"
project = "<Your Project Name>"
workitem_type = "Bug"
PAT = "<Your Personal Access Token>"
url = "https://dev.azure.com/"+organization+"/"+project+"/_apis/wit/workitems/$"+workitem_type+"?api-version=6.0"
payload = json.dumps([
{
"op": "add",
"path": "/fields/System.Title",
"from": None,
"value": "Sample task"
}
])
headers = {
'Content-Type': 'application/json-patch+json',
'Authorization': 'Basic '+PAT
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.