Error while creating azure devops release pipeline - POST rest api - azure

Facing an issue while creating a ADO release pipeline - with powershell ADO rest API.
Below is the code -
[string]$organisation = "",
[string]$project = "",
[string]$keepForever = "true",
[string]$user = "",
[string]$token = "")
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$postresults = "https://vsrm.dev.azure.com/$organisation/$project/_apis/release/definitions?api-version=5.0"
$body = #{
"name"="New release pipeline russ"
"comment"="test"
"environments"=#{
"name"="DEV"
}
"path"="\\"
"releaseNameFormat"="Release"
"description"=""
} | ConvertTo-Json
$result = Invoke-RestMethod -Uri $postresults -Method Post -Body $body -ContentType "application/json" -Headers #{Authorization=("Basic {0}" -f $base64AuthInfo)}
And the error that I got is --
Invoke-RestMethod : {"$id":"1","innerException":null,"message":"VS402875:
Release pipeline needs to have at least one stage. Add a stage and try again.",
"typeName":"Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.I
nvalidRequestException, Microsoft.VisualStudio.Services.ReleaseManagement2.Data
","typeKey":"InvalidRequestException","errorCode":0,"eventId":3000}
At line:27 char:1
Found similar issue in VS developer community blog, unfortunately no help in it -
https://developercommunity.visualstudio.com/content/problem/582209/post-example-to-create-a-release-pipeline.html
Any inputs are much appreciate .
Thanks,

The environments in the body should include at least name, preDeployApprovals, postDeployApprovals, deployPhases, retentionPolicy, otherwise, you'll get error. The body should look like below:
{
"name": "New release pipeline russ",
"comment": "test",
"environments": [
{
"name": "PROD",
"preDeployApprovals": {
"approvals": [
{
"rank": 1,
"isAutomated": false,
"isNotificationOn": false,
"approver": {
"displayName": null,
"id": "aeb95c63-4fac-4948-84ce-711b0a9dda97"
},
"id": 0
}
]
},
"postDeployApprovals": {
"approvals": [
{
"rank": 1,
"isAutomated": true,
"isNotificationOn": false,
"id": 0
}
]
},
"deployPhases": [
{
"deploymentInput": {
"parallelExecution": {
"parallelExecutionType": "none"
},
"skipArtifactsDownload": false,
"artifactsDownloadInput": {},
"queueId": 391,
"demands": [],
"enableAccessToken": false,
"timeoutInMinutes": 0,
"jobCancelTimeoutInMinutes": 1,
"condition": "succeeded()",
"overrideInputs": {}
},
"rank": 1,
"phaseType": "agentBasedDeployment",
"name": "Run on agent",
"workflowTasks": []
}
],
"retentionPolicy": {
"daysToKeep": 30,
"releasesToKeep": 3,
"retainBuild": true
}
}
],
"path": "\\",
"releaseNameFormat": "Release",
"description": ""
}

Related

Read/Save Azure DevOps pipeline variable in shell script

I am using Azure DevOps for some application deployment. I need to have a saved variable build number that would update every time I do a build successfully and send the apk/ipa to the store.
Right now, from what I read in the Azure documentation and other post on StackOverflow about this, I setup my scripts this way.
This is my pipeline variable
This is my current script
the output is:
So, it seems to update my local variable but not my pipeline variable. I am unsure why since this is the example provided EVERYWHERE.
Sources:
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/set-variables-scripts?view=azure-devops&tabs=bash
how to increment and save variable in azure devops pipeline
Thank you for the help!
Edit 1: Ok, so it seems that there is a variable/function called counter. I haven't figured out how to use it yet, but looking into it.
Edit 2:
Updated my azure-pipelines.yml
variables:
major: 1
minor: 0
patch: 0
build: $[counter(variables['patch'], 1)]
On my pipeline it looks like this
and my fastlane (ruby script ) lane looks like this
lane :tf do
`echo $major`
`echo $minor`
`echo $patch`
`echo $build` # Nothing
`echo $MAJOR`
`echo $MINOR`
`echo $PATCH`
`echo $BUILD` # Nothing
`echo $(major)` # fails
end
those show nothing.
This azure DevOps is very depressing. It says here I can do a bash call to this variable.
Variables used with macro syntax are expanded in runtime before task is executed, that is why there is value '1' in last log, even when value previously was set in previous step to '2'.
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#runtime-expression-syntax
Try to use runtime expression instead, it is expanded in runtime
Two solutions for you.
1. Use counter expression.
counter(<prefix>, <feed>)
counter expression is for pipeline, and it has two parameters, prefix and seed. Seed is based on the prefix.
When the prefix is been set and run for the first time, the counter result will start from the feed value. But for the later run based on the same prefix, the counter result will ignore the feed value, it will be 'last time counter result + 1'
2, Change the pipeline definition directly.
For example, I can use the below python code to get and change the variable of classic pipeline:
import json
import requests
org_name = "xxx"
project_name = "xxx"
pipeline_definition_id = "xxx"
personal_access_token = "xxx"
key = 'variables'
var_name = 'BUILDNUMBER'
url = "https://dev.azure.com/"+org_name+"/"+project_name+"/_apis/build/definitions/"+pipeline_definition_id+"?api-version=6.0"
payload={}
headers = {
'Authorization': 'Basic '+personal_access_token
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
json_content = response.text
def get_content_of_json(json_content, key, var_name):
data = json.loads(json_content)
return data[key][var_name].get('value')
def change_content_of_json(json_content, key, var_name):
data = json.loads(json_content)
data[key][var_name]['value'] = str(int(get_content_of_json(json_content,key,var_name)) + 1)
return data
json_data = change_content_of_json(json_content, key, var_name)
url2 = "https://dev.azure.com/"+org_name+"/"+project_name+"/_apis/build/definitions/"+pipeline_definition_id+"?api-version=6.0"
payload2 = json.dumps(json_data)
headers2 = {
'Authorization': 'Basic '+personal_access_token,
'Content-Type': 'application/json'
}
response2 = requests.request("PUT", url2, headers=headers2, data=payload2)
Write a JSON demo for you, you can import it in your DevOps and design yourself classic pipeline based on this:
{
"options": [
{
"enabled": false,
"definition": {
"id": "5d58cc01-7c75-450c-be18-a388ddb129ec"
},
"inputs": {
"branchFilters": "[\"+refs/heads/*\"]",
"additionalFields": "{}"
}
},
{
"enabled": false,
"definition": {
"id": "a9db38f9-9fdc-478c-b0f9-464221e58316"
},
"inputs": {
"workItemType": "Bug",
"assignToRequestor": "true",
"additionalFields": "{}"
}
}
],
"variables": {
"BUILDNUMBER": {
"value": "7"
},
"system.debug": {
"value": "false",
"allowOverride": true
}
},
"properties": {},
"tags": [],
"_links": {
"self": {
"href": "https://dev.azure.com/BowmanCP/c6358b04-e91a-4bd1-a894-1adb543134d6/_apis/build/Definitions/359?revision=11"
},
"web": {
"href": "https://dev.azure.com/BowmanCP/c6358b04-e91a-4bd1-a894-1adb543134d6/_build/definition?definitionId=359"
},
"editor": {
"href": "https://dev.azure.com/BowmanCP/c6358b04-e91a-4bd1-a894-1adb543134d6/_build/designer?id=359&_a=edit-build-definition"
},
"badge": {
"href": "https://dev.azure.com/BowmanCP/c6358b04-e91a-4bd1-a894-1adb543134d6/_apis/build/status/359"
}
},
"jobAuthorizationScope": 2,
"jobTimeoutInMinutes": 60,
"jobCancelTimeoutInMinutes": 5,
"process": {
"phases": [
{
"steps": [
{
"environment": {},
"enabled": true,
"continueOnError": false,
"alwaysRun": false,
"displayName": "PowerShell Script",
"timeoutInMinutes": 0,
"retryCountOnTaskFailure": 0,
"condition": "succeeded()",
"task": {
"id": "e213ff0f-5d5c-4791-802d-52ea3e7be1f1",
"versionSpec": "2.*",
"definitionType": "task"
},
"inputs": {
"targetType": "inline",
"filePath": "",
"arguments": "",
"script": "# Write your PowerShell commands here.\n\nWrite-Host \"Hello World\"\n\npip install requests\n",
"errorActionPreference": "stop",
"warningPreference": "default",
"informationPreference": "default",
"verbosePreference": "default",
"debugPreference": "default",
"progressPreference": "silentlyContinue",
"failOnStderr": "false",
"showWarnings": "false",
"ignoreLASTEXITCODE": "false",
"pwsh": "false",
"workingDirectory": "",
"runScriptInSeparateScope": "false"
}
},
{
"environment": {},
"enabled": true,
"continueOnError": false,
"alwaysRun": false,
"displayName": "Run a Python script",
"timeoutInMinutes": 0,
"retryCountOnTaskFailure": 0,
"condition": "succeeded()",
"task": {
"id": "6392f95f-7e76-4a18-b3c7-7f078d2f7700",
"versionSpec": "0.*",
"definitionType": "task"
},
"inputs": {
"scriptSource": "inline",
"scriptPath": "",
"script": "import json\nimport requests\n\n\norg_name = \"BowmanCP\"\nproject_name = \"BowmanCP\"\npipeline_definition_id = \"359\"\npersonal_access_token = \"OnhlbXFzd29hdXJrdGhvNGJhemJza3hhenZldnRhbXhhZTVhNDMycXZoNzRicmo3YTZjc3E=\"\n\nkey = 'variables'\nvar_name = 'BUILDNUMBER'\n\nurl = \"https://dev.azure.com/\"+org_name+\"/\"+project_name+\"/_apis/build/definitions/\"+pipeline_definition_id+\"?api-version=6.0\"\n\npayload={}\nheaders = {\n 'Authorization': 'Basic '+personal_access_token\n}\n\nresponse = requests.request(\"GET\", url, headers=headers, data=payload)\nprint(response.text)\njson_content = response.text\ndef get_content_of_json(json_content, key, var_name):\n data = json.loads(json_content)\n return data[key][var_name].get('value')\n\ndef change_content_of_json(json_content, key, var_name):\n data = json.loads(json_content)\n data[key][var_name]['value'] = str(int(get_content_of_json(json_content,key,var_name)) + 1)\n return data\n\njson_data = change_content_of_json(json_content, key, var_name)\n\n\nurl2 = \"https://dev.azure.com/\"+org_name+\"/\"+project_name+\"/_apis/build/definitions/\"+pipeline_definition_id+\"?api-version=6.0\"\n\npayload2 = json.dumps(json_data)\nheaders2 = {\n 'Authorization': 'Basic '+personal_access_token,\n 'Content-Type': 'application/json'\n}\n\nresponse2 = requests.request(\"PUT\", url2, headers=headers2, data=payload2)\n",
"arguments": "",
"pythonInterpreter": "",
"workingDirectory": "",
"failOnStderr": "false"
}
}
],
"name": "Agent job 1",
"refName": "Job_1",
"condition": "succeeded()",
"target": {
"executionOptions": {
"type": 0
},
"allowScriptsAuthAccessOption": false,
"type": 1
},
"jobAuthorizationScope": 2
}
],
"target": {
"agentSpecification": {
"identifier": "windows-2019"
}
},
"type": 1
},
"repository": {
"properties": {
"cleanOptions": "0",
"labelSources": "0",
"labelSourcesFormat": "$(build.buildNumber)",
"reportBuildStatus": "true",
"fetchDepth": "1",
"gitLfsSupport": "false",
"skipSyncSource": "false",
"checkoutNestedSubmodules": "false"
},
"id": "421488b2-be68-4b8e-8faf-8302da314071",
"type": "TfsGit",
"name": "XunitTest_Auto",
"url": "https://dev.azure.com/BowmanCP/BowmanCP/_git/XunitTest_Auto",
"defaultBranch": "refs/heads/main",
"clean": "false",
"checkoutSubmodules": false
},
"processParameters": {},
"quality": 1,
"authoredBy": {
"displayName": "Bowman Zhu",
"url": "https://spsprodsea2.vssps.visualstudio.com/A64545e3d-c12d-4c81-b77f-4de83783d9bd/_apis/Identities/af91e22a-cc35-4c8e-8af3-f49c4a1b9b6a",
"_links": {
"avatar": {
"href": "https://dev.azure.com/BowmanCP/_apis/GraphProfile/MemberAvatars/aad.ZGU3N2NiY2YtZTgzYy03ZDkwLWI0YTYtOTk3Nzg3NDczMzBl"
}
},
"id": "af91e22a-cc35-4c8e-8af3-f49c4a1b9b6a",
"uniqueName": "xxx#xxx.com",
"imageUrl": "https://dev.azure.com/BowmanCP/_apis/GraphProfile/MemberAvatars/aad.ZGU3N2NiY2YtZTgzYy03ZDkwLWI0YTYtOTk3Nzg3NDczMzBl",
"descriptor": "aad.ZGU3N2NiY2YtZTgzYy03ZDkwLWI0YTYtOTk3Nzg3NDczMzBl"
},
"drafts": [],
"queue": {
"_links": {
"self": {
"href": "https://dev.azure.com/BowmanCP/_apis/build/Queues/18"
}
},
"id": 18,
"name": "Azure Pipelines",
"url": "https://dev.azure.com/BowmanCP/_apis/build/Queues/18",
"pool": {
"id": 9,
"name": "Azure Pipelines",
"isHosted": true
}
},
"id": 359,
"name": "ChangeVariable",
"url": "https://dev.azure.com/BowmanCP/c6358b04-e91a-4bd1-a894-1adb543134d6/_apis/build/Definitions/359?revision=11",
"uri": "vstfs:///Build/Definition/359",
"path": "\\",
"type": 2,
"queueStatus": 0,
"revision": 11,
"createdDate": "2022-11-07T10:14:18.003Z",
"project": {
"id": "c6358b04-e91a-4bd1-a894-1adb543134d6",
"name": "BowmanCP",
"url": "https://dev.azure.com/BowmanCP/_apis/projects/c6358b04-e91a-4bd1-a894-1adb543134d6",
"state": 1,
"revision": 178,
"visibility": 0,
"lastUpdateTime": "2022-09-05T06:02:02.693Z"
}
}
it seems to update my local variable but not my pipeline variable
Refer to this doc: Set variables in scripts
A script in your pipeline can define a variable so that it can be consumed by one of the subsequent steps in the pipeline.Set variables in scripts
The method you used to update the Pipeline Variable value is correct.
It will not work on the current task, but the updated value can be used in the next tasks.
For example:
steps:
- bash: |
echo $(TestVariable)
echo "##vso[task.setvariable variable=TestVariable;]2"
displayName: 'Bash Script'
- bash: |
echo $(TestVariable)
For the requirement about using counter expression, you can refer to my another ticket: Azure DevOps: release version
I eventually used this formula that works without having to hack the NSA and FBI to get a build number updated. It's not exactly what I wanted, but whatever, I will deal with this atm.
then using the ENV['BUILDNUMBER'] in my ruby script, and it reads the env variable with the counter. It is the type of solution I needed, although it doesn't do exactly what I want.

How can i extract data from a Powershell command result? [duplicate]

I have json body in powershell variable and want to get value from it.
Json Body :
"value": [
{
"id": 1,
"scope": "3e93f9e6-f427-48e1-b37b-994d196e1121",
"name": "Default",
"isHosted": false,
"poolType": "automation",
"size": 3
},
{
"id": 2,
"scope": "3e93f9e6-f427-48e1-b37b-994d196e1121",
"name": "Hosted",
"isHosted": true,
"poolType": "automation",
"size": 10
},
{
"id": 4,
"scope": "3e93f9e6-f427-48e1-b37b-994d196e1121",
"name": "Hosted VS2017",
"isHosted": true,
"poolType": "automation",
"size": 10
}]
I want to get the id value where name=Hosted VS2017 i.e 4
powershell :
Write-Host "json body:" $projects
$id = $projects.value | where { $_.name -eq "Hosted VS2017" }
Write-Host "id :" $id
You need to convert your JSON into a powershell object before you can work with it:
$projects = $projects | ConvertFrom-Json
Then you can access its members:
#requires -Version 3
$projects.value | ? name -eq 'Hosted VS2017'

powershell output not array type but string type?

Hi I'm writing a script to call to AZ migration api
$siteuri= 'https://management.azure.com/subscriptions/' + $metadata.compute.subscriptionID +'/resourceGroups/' + $AzMigreateResourceGroup+ '/providers/Microsoft.Migrate/migrateProjects/' + $ProjectName + '/solutions/Servers-Discovery-ServerDiscovery?api-version=2018-09-01-preview'
$siteoutput=(Invoke-RestMethod -Headers $Authtoken -uri $siteuri).properties.details.extendeddetails.applianceNameToSiteIdMapV3
the result I get is this
[
{
"lab3dev-app01": {
"ApplianceName": "xxx",
"SiteId": "xxx",
"KeyVaultId": "xxx",
"KeyVaultUrl": "xxx",
"ApplianceDetails": {
"machineID": "xxx",
"IPAddress": "192.168.50.210",
"HostName": "WIN-ETP6NTN8B65",
"isRegistered": true,
"discoveryStatus": "Success",
"deepDiscoveryDisabled": false
},
"CertificateContents": {
"xxx": ""
},
"AadAppDetails": {
"TenantID": "xxx",
"AppName": "xxx",
"AppID": "xxx",
"ObjectID": "xxx"
},
"ScaleOutList": null,
"isV2Site": false
}
},
{
"l3devhyper01": {
"ApplianceName": "xxx",
"SiteId": "xxx",
"KeyVaultId": "xxx",
"KeyVaultUrl": "xxx",
"ApplianceDetails": {
"machineID": "xxx",
"IPAddress": "192.168.50.143",
"HostName": "WIN-PKKCDSLE6OD",
"isRegistered": true,
"discoveryStatus": "Success",
"deepDiscoveryDisabled": false
},
"CertificateContents": {
"l3devhyper017a74agentauthcertv2": ""
},
"AadAppDetails": {
"TenantID": "xxx",
"AppName": "xxx",
"AppID": "xxx",
"ObjectID": "xxx"
},
"ScaleOutList": null,
"isV2Site": false
}
}
]
I was hoping this can be an array type, so I can do some search, but gettype() tells me this is a string?
is there anyway to output this as array not a string?
Invoke-RestMethod does return a Object, you're even using it to access a particular property. You'd need to have a look at the API description to see whenever it's just a string attribute (as that might be the case).
As you can see from that string that it is a JSON object you could use ConvertFrom-Json to turn it into an object.
The easiest case without additional error handling would be:
$siteoutput = Invoke-RestMethod -Headers $Authtoken -uri $siteuri
$siteoutput = $siteoutput.properties.details.extendeddetails.applianceNameToSiteIdMapV3 | ConvertFrom-Json

Azure Logic App, deployed using DevOps, first step "When a HTTP request is received", how to get the URL as output variable

Long title: Azure Logic App, deployed using DevOps, first step "When a HTTP request is received", how to get the URL as output variable for use in deployment of App Service calling this Logic App?
My azure application is composed of two parts:
a Logic App
an App Service (web)
which are both deployed using DevOps.
The first step of the logic app is "When a HTTP request is received".
The web has a dependency on the generated url
(e.g. https://prod-23.usgovarizona.logic.azure.us:443/workflows/.../triggers/request/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Frequest%2Frun&sv=1.0&sig=...) of the logic app.
How do I get the URL of the logic apps' first step as an output variable,
so that I can supply that value in the deployment of the App Service,
which calls the Logic App?
I looked at https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-outputs?tabs=azure-powershell but that didn't help me.
release.json
{
"source": 2,
"revision": 59,
"description": null,
"lastRelease": {
"id": 853,
"name": "Release-37",
"artifacts": [],
"_links": {},
"description": "Triggered by SMS Scheduler 2020.206.01.",
"releaseDefinition": {
"id": 14,
"projectReference": null,
"_links": {}
},
},
"variables": {
"depr_AppTeam": {
"value": "SDIS"
},
"depr_DeptAbbr": {
"value": "ENT"
},
"depr_ResourceGroupName": {
"value": "$AppTeam+ \"-\"+ $AppName +\"-\"+$Env + \"-rg\""
}
},
"variableGroups": [
43
],
"environments": [
{
"id": 24,
"name": "DEV",
"rank": 1,
"variables": {},
"variableGroups": [],
"deployStep": {
"id": 90
},
"deployPhases": [
{
"deploymentInput": {
"parallelExecution": {
"parallelExecutionType": 0
},
"agentSpecification": {
"identifier": "vs2017-win2016"
},
"skipArtifactsDownload": false,
"artifactsDownloadInput": {
"downloadInputs": []
},
"queueId": 64,
"demands": [],
"enableAccessToken": false,
"timeoutInMinutes": 0,
"jobCancelTimeoutInMinutes": 1,
"condition": "succeeded()",
"overrideInputs": {}
},
"rank": 1,
"phaseType": 1,
"name": "Agent job",
"refName": null,
"workflowTasks": [
{
"environment": {},
"taskId": "94a...",
"version": "2.*",
"name": "Azure Deployment:Create Or Update Resource Group action on $(AppTeam)-$(AppName)-$(Release.EnvironmentName)-rg",
"refName": "",
"enabled": true,
"alwaysRun": false,
"continueOnError": false,
"timeoutInMinutes": 0,
"definitionType": "task",
"overrideInputs": {},
"condition": "succeeded()",
"inputs": {
"ConnectedServiceName": "nov...",
"action": "Create Or Update Resource Group",
"resourceGroupName": "$(AppTeam)-$(AppName)-$(Release.EnvironmentName)-rg",
"location": "USGov Arizona",
"templateLocation": "Linked artifact",
"csmFileLink": "",
"csmParametersFileLink": "",
"csmFile": "$(System.DefaultWorkingDirectory)/_ent_sms_scheduler/Job1/template.json",
"csmParametersFile": "$(System.DefaultWorkingDirectory)/_ent_sms_scheduler/Job1/parameters.json",
"overrideParameters": "",
"deploymentMode": "Incremental",
"enableDeploymentPrerequisites": "None",
"deploymentGroupEndpoint": "",
"project": "",
"deploymentGroupName": "",
"copyAzureVMTags": "true",
"runAgentServiceAsUser": "false",
"userName": "",
"password": "",
"outputVariable": "",
"deploymentName": "",
"deploymentOutputs": "",
"addSpnToEnvironment": "false"
}
},
]
}
],
},
],
"triggers": [
{
"artifactAlias": "_ent_sms_scheduler",
"triggerConditions": [],
"triggerType": 1
}
],
"releaseNameFormat": "Release-$(rev:r)",
"tags": [],
"properties": {
"DefinitionCreationSource": {
"$type": "System.String",
"$value": "ReleaseNew"
},
"IntegrateJiraWorkItems": {
"$type": "System.String",
"$value": "false"
},
"IntegrateBoardsWorkItems": {
"$type": "System.String",
"$value": "False"
}
},
"id": 14,
"name": "SMS SCHEDULER",
"path": "\\",
"projectReference": null,
"url": "https://vsrm.dev.azure.com/.../.../_apis/Release/definitions/14",
"_links": {
"self": {
"href": "https://vsrm.dev.azure.com/.../.../_apis/Release/definitions/14"
},
"web": {
"href": "https://dev.azure.com/.../.../_release?definitionId=14"
}
}
}
release task:
steps:
- task: AzureResourceGroupDeployment#2
displayName: 'Azure Deployment:Create Or Update Resource Group action on $(AppTeam)-$(AppName)-$(Release.EnvironmentName)-rg'
inputs:
azureSubscription: 'ENT-eComm-Deployment-NonProd-Gov-Connection'
resourceGroupName: '$(AppTeam)-$(AppName)-$(Release.EnvironmentName)-rg'
location: 'USGov Arizona'
csmFile: '$(System.DefaultWorkingDirectory)/_ent_sms_scheduler/Job1/template.json'
csmParametersFile: '$(System.DefaultWorkingDirectory)/_ent_sms_scheduler/Job1/parameters.json'
It seems that you deploy Azure Logic App first, and then App Service.
You can add an Azure Powershell task after you deploy the Azure Logic app. Call Get-AzLogicAppTriggerCallbackUrl
command to get specific Logic App trigger callback URL. Example:
Get-AzLogicAppTriggerCallbackUrl -ResourceGroupName "ResourceGroup11" -Name "LogicApp1" -TriggerName "manual"
Value
-----
https://prod-03.westus.logic.azure.com:443/workflows/c4ed9335bc864140a11f4508d19acea3/triggers/manual/run?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=
And then you can define variables whose value is the response URL. Follow use variables as inputs and detailed sample to output this variable to following tasks.

Azure DevOps Wiql API add fields to Response workItems

I'm looking a way (or Query) to add the workItem Fields on the response of this query:
{
"query": "Select [System.Id], [System.Title] From WorkItems Where [System.WorkItemType] = 'Task' OR [System.WorkItemType] = 'Bug'"
}
Current Response:
{
"queryType": "flat",
"queryResultType": "workItem",
"asOf": "2020-08-17T15:13:32.75Z",
"columns": [
{
"referenceName": "System.Id",
"name": "ID",
"url": "https://dev.azure.com/.../_apis/wit/fields/System.Id"
},
{
"referenceName": "System.Title",
"name": "Title",
"url": "https://dev.azure.com/..._apis/wit/fields/System.Title"
}
],
"workItems": [
{
"id": 27,
"url": "https://dev.azure.com/.../_apis/wit/workItems/27"
},
{
"id": 44,
"url": "https://dev.azure.com/.../_apis/wit/workItems/44"
}
]
}
I need to expand Fields on each workItem found like i would be doing a GET workitems API request, even if its possible to ?$expand=relations
This would be my expected output on WorkItems
Expected Response:
{
"queryType": "flat",
"queryResultType": "workItem",
"asOf": "2020-08-17T15:13:32.75Z",
"columns": [
{
"referenceName": "System.Id",
"name": "ID",
"url": "https://dev.azure.com/.../_apis/wit/fields/System.Id"
},
{
"referenceName": "System.Title",
"name": "Title",
"url": "https://dev.azure.com/.../_apis/wit/fields/System.Title"
}
],
"workItems": [
{
"id": 27,
"rev": 22,
"fields": {
"System.AreaPath": "Cloud",
"System.TeamProject": "Cloud",
"System.IterationPath": "Cloud\\Sprint 6",
"System.WorkItemType": "Task",
"System.State": "Closed",
"System.Reason": "Completed",
"System.AssignedTo": {...},
"System.CreatedDate": "2020-02-24T15:52:08.867Z",
"System.CreatedBy": {...},
"System.ChangedDate": "2020-06-24T14:48:26.593Z",
"System.ChangedBy": {...},
"System.CommentCount": 6,
"System.Title": "Add XCAL import support to AAT3 framework and GUI",
"Microsoft.VSTS.Common.StateChangeDate": "2020-06-24T14:48:26.593Z",
"Microsoft.VSTS.Common.ActivatedDate": "2020-06-03T00:47:20.397Z",
"Microsoft.VSTS.Common.ActivatedBy": {...},
"Microsoft.VSTS.Common.ClosedDate": "2020-06-24T14:48:26.593Z",
"Microsoft.VSTS.Common.ClosedBy": {...},
"Microsoft.VSTS.Common.Priority": 2,
"Microsoft.VSTS.Common.ValueArea": "Business",
"WEF_DA224280DD46429CA75C96DC1082D816_Kanban.Column": "New",
"WEF_DA224280DD46429CA75C96DC1082D816_Kanban.Column.Done": false,
"System.Description": "...",
"System.Parent": 45
},
"relations": [...],
"_links": {...},
"url": "...workItems/27"
},
{
"id": 44,
...
}
]
}
I am afraid that the WIQL Rest API couldn't return the detailed work item information.
But you could use the WIQL Get the work item ids and send the ids to Work item -List. In this case, you could get the work item information.
Here is a PowerShell Script sample:
$token = "PAT"
$url="https://dev.azure.com/Organizationname/_apis/wit/wiql?api-version=5.1"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$JSON = #'
{
"query": "SELECT [System.Id], [System.WorkItemType], [System.State],[System.AreaPath],[System.Tags],[System.CommentCount],[System.ChangedDate] FROM workitems WHERE[System.Id] IN(#follows) AND [System.TeamProject] = 'Azure' AND [System.State] <> '' ORDER BY [System.ChangedDate] DESC"
}
'#
$response = Invoke-RestMethod -Uri $url -Headers #{Authorization = "Basic $token"} -Method Post -Body $JSON -ContentType application/json
$listOfTasks = New-Object Collections.Generic.List[String]
ForEach( $workitem in $response.workItems ) {
$listOfTasks.Add($workitem.id)
}
$listOfTasks = $listOfTasks -join ','
$listOfTasks
$url1="https://dev.azure.com/Organizationname/ProjectName/_apis/wit/workitems?ids=$listOfTasks" +"&" + "`$expand" + "=all&api-version=5.1"
$response1 = Invoke-RestMethod -Uri $url1 -Headers #{Authorization = "Basic $token"} -Method Get
Write-Host "result = $($response1 | ConvertTo-Json -Depth 100)"
Explaination:
The first part is to get the workitem id output by wiql.
The second part is to add work item id list to work item list api to obtain specific information of all work items.
Here is the result:

Resources