Populate picklist dynamically based on filepath type in Azure Devops? - azure-devops

In Azure Devops, I am building one extension with build task where input picklist field is dependent on the another input filepath field.
When the user provides an input filepath, I wanted to dynamically read and populate the picklist with new items.
I tried to search and implement but couldn't find a way.
Any help or guidance will be appreciated. I found the below example to help me out for static values.
{
"name": "action",
"type": "pickList",
"label": "Action",
"defaultValue": "Publish",
"required": true,
"helpMarkDown": "Select the Action to perform",
"options": {
"Publish": "Publish Changes",
"Script": "Script Changes",
"DeployReport": "Generate Deployment Report"
}
}

The out-of-box tasks are open source, so you can take a look through the repository to get some ideas of the patterns they use. Here is an example from the Download Build Artifacts task. The build definition is dependent on the project that is defined.
{
"name": "project",
"type": "pickList",
"label": "Project",
"defaultValue": "",
"required": true,
"visibleRule": "buildType == specific",
"properties": {
"EditableOptions": "True",
"DisableManageLink": "True"
},
"helpMarkDown": "The project from which to download the build artifacts"
},
{
"name": "definition",
"aliases": [
"pipeline"
],
"type": "pickList",
"label": "Build pipeline",
"defaultValue": "",
"required": true,
"visibleRule": "buildType == specific",
"properties": {
"EditableOptions": "True",
"DisableManageLink": "True",
"IsSearchable": "True"
},
"helpMarkDown": "Select the build pipeline name"
},
Then in the dataSourceBindings section believe it uses the target from the previous selection as a parameter input.
"dataSourceBindings": [
{
"endpointId": "tfs:teamfoundation",
"target": "project",
"endpointUrl": "{{endpoint.url}}/_apis/projects?$skip={{skip}}&$top=1000",
"resultSelector": "jsonpath:$.value[?(#.state=='wellFormed')]",
"resultTemplate": "{ \"Value\" : \"{{{id}}}\", \"DisplayValue\" : \"{{{name}}}\" }",
"callbackContextTemplate": "{\"skip\": \"{{add skip 1000}}\"}",
"callbackRequiredTemplate": "{{isEqualNumber result.count 1000}}",
"initialContextTemplate": "{\"skip\": \"0\"}"
},
{
"endpointId": "tfs:teamfoundation",
"target": "definition",
"endpointUrl": "{{endpoint.url}}/{{project}}/_apis/build/definitions?api-version=3.0-preview&$top=500&continuationToken={{{continuationToken}}}&name=*{{name}}*&queryOrder=2",
"resultSelector": "jsonpath:$.value[?(#.quality=='definition')]",
"parameters": {
"project": "$(project)",
"name": "$(name)"
},
"resultTemplate": "{ \"Value\" : \"{{{id}}}\", \"DisplayValue\" : \"{{{name}}}\" }",
"callbackContextTemplate": "{\"continuationToken\" : \"{{{headers.x-ms-continuationtoken}}}\"}",
"callbackRequiredTemplate": "{{{#headers.x-ms-continuationtoken}}}true{{{/headers.x-ms-continuationtoken}}}",
"initialContextTemplate": "{\"continuationToken\" : \"{{{system.utcNow}}}\"}"
},

Related

How get the latest value in pick list

I'm trying to develop an extension/pipeline task for Azure DevOps for release gates. Not getting how to bind the the latest value to the pick list as shown here:
Each time a build completes, pick list should have latest build Id as the selected value.
Here is the code snippet i tried,
This creates a pick list
{
"name": "buildId",
"type": "pickList",
"label": "Artifact",
"required": true,
"defaultValue": "Latest",
"properties": {
"DisableManageLink": "True",
"EditableOptions": "True"
}
"helpMarkDown": "Build Artifacts"
},
this binds the values for the picklist
{
"target": "buildId",
"endpointId": "tfs:teamfoundation",
"endpointUrl": "{{endpoint.url}}/{{system.teamProject}}/_apis/build/builds?api-version=5.0",
"resultSelector": "jsonpath:$.value[*]",
"resultTemplate": "{ \"Value\" : \"{{{id}}}\", \"DisplayValue\" : \"{{{buildNumber}}} \" }"
}
Let me know if there are any way to get this.
I afraid you will need to implement your own code methods to bind latest value to the latest buildid.
For example in Publish build artifacts task. The latest build id is retrieved according to the selected value(ie. latest) of field buildVersionToDownload: See below:
buildVersionToDownload has three options.
{
"name": "buildVersionToDownload",
"type": "pickList",
"label": "Build version to download",
"defaultValue": "latest",
"visibleRule": "buildType == specific",
"required": true,
"options": {
"latest": "Latest",
"latestFromBranch": "Latest from specific branch and specified Build Tags",
"specific": "Specific version"
}
}
If the buildVersionToDownload value is selected as specific. Then it is required to select the build id in the Build picklist.
{
"name": "buildId",
"type": "pickList",
"label": "Build",
"defaultValue": "",
"required": true,
"visibleRule": "buildType == specific && buildVersionToDownload == specific",
"properties": {
"EditableOptions": "True",
"DisableManageLink": "True"
},
"helpMarkDown": "The build from which to download the artifacts"
}
buildVersionToDownload is not bound to dataSource, only buildId is bound:
{
"endpointId": "tfs:teamfoundation",
"target": "buildId",
"endpointUrl": "{{endpoint.url}}/{{project}}/_apis/build/builds?definitions={{definition}}&resultFilter=succeeded,partiallySucceeded&$top=200",
"resultSelector": "jsonpath:$.value[*]",
"parameters": {
"project": "$(project)",
"definition": "$(definition)"
},
"resultTemplate": "{ \"Value\" : \"{{{id}}}\", \"DisplayValue\" : \"{{{buildNumber}}}\" }"
}
See here for more information.
If buildVersionToDownload is selected as latest. Then the latest build id is retrieved via code. See code example here
So that in your custom task. When the Default Version is latest. You can get the latest build id in your code methods. And when Default Version is not latest. Then make the Artifact visible to select a build id from the picklist.

Extensibility point on release results page

I am part of VS performance team, I need to create a new tab for the Release result page.Release result page
Previously it was possible with the target ms.vss-releaseManagement-web.release-details-view but that no longer works on the new experience, do you know how the contribution configuration should look?, this is what I have so far:
"id": "pit-tab",
"type": "ms.vss-releaseManagement-web.release-summary-tab",
"targets": [
"ms.vss-releaseManagement-web.release-details-view"
],
"properties": {
"name": "Performance",
"uri": "dist/index.html",
"order": "99",
"icon": "asset://img/icon.png",
"supportsMobile": true
}
Try with below script:
{
"id": "release-environments-tab",
"type": "ms.vss-web.tab",
"description": "Adds a 'Merlin Insert' tab to the release environment.",
"targets": [
"ms.vss-releaseManagement-web.release-environment-editor-tab"
],
"properties": {
"name": "Merlin Insert",
"order": "30",
"uri": "index.html"
}
},

Azure DevOps API - how to discover link between field and picklist

I'm trying to replicate an Azure DevOps process from one organization to another via the AZDO REST Api. I'm working on replicating the layout and am stuck because I can't discover the relationship between a custom field and a picklist when querying the source AZDO instance.
In my scenario I have a test work item type which I've called Issue. On the Issue interface I've created a custom field which is a picklist. While I can retrieve a list of lists via the Rest API and examine the field as well, I can't figure out how the two are related.
Here is a partial payload from the field:
{
"count": 39,
"value": [
...
{
"referenceName": "Custom.IssueSource",
"name": "Issue Source",
"type": "string",
"description": "Who is this attributed to",
"required": true,
"url": "https://dev.azure.com/MYORG/_apis/work/processes/f390103e-7097-4f19-b5b5-f9dbcf92bb6f/behaviors",
"customization": "custom"
},
... ]
}
and here is a partial payload from the lists get query which I used trial and error to determine was the picklist I've assigned:
{
"count": 10,
"value": [
...
{
"id": "2998d4e4-2bec-4935-98a1-b67a0b0b6d5d",
"name": "picklist_e854661e-8620-4ad9-be28-b974c5cb3a5d",
"type": "String",
"isSuggested": false,
"url": "https://dev.azure.com/MYORG/_apis/work/processes/lists/2998d4e4-2bec-4935-98a1-b67a0b0b6d5d"
},
...
]
}
Here is a partial layout response for the WIT:
{
"pages": [
{
"id": "d0171d51-ff84-4038-afc1-8800ab613160.System.WorkItemType.Details",
"inherited": true,
"label": "Details",
"pageType": "custom",
"visible": true,
"isContribution": false,
"sections": [
{
"id": "Section1",
"groups": [
...
{
"id": "bf03e049-5062-4d82-b91d-4396541fbed2",
"label": "Custom",
"isContribution": false,
"visible": true,
"controls": [
{
"id": "Custom.IssueSource",
"label": "Issue Source",
"controlType": "FieldControl",
"readOnly": false,
"visible": true,
"isContribution": false
}
]
}
]
},
... ]
}
Using fiddler against the AZDO web interface, the only time I see a reference to the picklist is from another non-AZDO API to https://dev.azure.com/MYORG/_apis/Contribution/dataProviders/query
Is there a way to discover the link via the AZDO Rest API? I saw this question which was similar but was about creating the link
Figured it out. Turns out you need to query from a different scope - work item tracking rather than work item tracking process:
https://dev.azure.com/MYORG/_apis/wit/fields/Custom.IssueSource?api-version=5.0-preview.2
returns
{
"name": "Issue Source",
"referenceName": "Custom.IssueSource",
"description": "Who is this attributed to",
"type": "string",
"usage": "workItem",
"readOnly": false,
"canSortBy": true,
"isQueryable": true,
...
"isIdentity": false,
--> "isPicklist": true,
"isPicklistSuggested": false,
--> "picklistId": "2998d4e4-2bec-4935-98a1-b67a0b0b6d5d",
"url": "https://dev.azure.com/MYORG/_apis/wit/fields/Custom.IssueSource"
}

Cannot use resultSelector while developing an Azure DevOps extension

I am working on a custom extension for Azure Devops which already contains a service endpoint:
"type": "ms.vss-endpoint.service-endpoint-type"
In addition, I would like to create a custom Release Artifact Source:
“type”: “ms.vss-releaseartifact.release-artifact-type”
Following this documentation, my current struggle is in filling the fields under the Artifact Source using an external API. I tried many patterns in the following ‘resultSelector’ and ‘resultTemplate’, but couldn’t hit one that worked for me.
In my example, I would like to take all the ‘uri’ values under ‘builds’ in the json response and present them in the ‘definition’ inputDescriptor of the Artifact Source. All my attempts resulted in an empty combo-box, even though I can see the request reaching the required API.
The json I would like to parse into the combo-box:
{
"builds": [
{
"uri": "/build1",
"lastStarted": "2018-11-07T13:12:42.547+0000"
},
{
"uri": "/build2",
"lastStarted": "2018-11-09T15:40:30.315+0000"
},
{
"uri": "/build3",
"lastStarted": "2018-11-12T17:46:24.805+0000"
}
],
"uri": "https://<server-address>/api/build"
}
Can you please help me create the Mustache pattern to retrieve the above "uri" values?
I tried:
$.builds[*].uri
which doesn't seem to work.
Here's some more information in case it helps.
Service endpoint's datasources:
"dataSources": [
{
"name": "TestConnection",
"endpointUrl": "{{endpoint.url}}/api/plugins",
"resourceUrl": "",
"resultSelector": "jsonpath:$.values[*]",
"headers": [],
"authenticationScheme": null
},
{
"name": "BuildNames",
"endpointUrl": "{{endpoint.url}}/api/build",
"resultSelector": "jsonpath:$.builds[*].uri"
},
{
"name": "BuildNumbers",
"endpointUrl": "{{endpoint.url}}/api/builds/{{definition}}",
"resultSelector": "jsonpath:$.buildsNumbers[*].uri"
}
]
Artifact source:
"inputDescriptors": [
{
"id": "connection",
"name": "Artifactory service",
"inputMode": "combo",
"isConfidential": false,
"hasDynamicValueInformation": true,
"validation": {
"isRequired": true,
"dataType": "string",
"maxLength": 300
}
},
{
"id": "definition",
"name": "definition",
"description": "Name of the build.",
"inputMode": "combo",
"isConfidential": false,
"dependencyInputIds": [
"connection"
],
"validation": {
"isRequired": true,
"dataType": "string",
"maxLength": 300
}
},
{
"id": "buildNumber",
"name": "Build Number",
"description": "Number of the build.",
"inputMode": "combo",
"isConfidential": false,
"dependencyInputIds": [
"connection"
],
"validation": {
"isRequired": true,
"dataType": "string",
"maxLength": 300
}
}
],
"dataSourceBindings": [
{
"target": "definition",
"dataSourceName": "BuildNames",
"resultTemplate": "{ Value : \"{{uri}}\", DisplayValue : \"{{uri}}\" }"
},
{
"target": "versions",
"dataSourceName": "BuildNumbers",
"resultTemplate": "{ Value : \"{{uri}}\", DisplayValue : \"{{uri}}\" }"
},
{
"target": "latestVersion",
"dataSourceName": "BuildNumbers",
"resultTemplate": "{ Value : \"{{uri}}\", DisplayValue : \"{{uri}}\" }"
},
{
"target": "artifactDetails",
"resultTemplate": "{ Name: \"{{version}}\", downloadUrl : \"{{endpoint.url}}\" }"
},
{
"target": "buildNumber",
"dataSourceName": "BuildNumbers",
"resultTemplate": "{ Value : \"{{uri}}\", DisplayValue : \"{{uri}}\" }"
}
]
}
Any help provided will be highly appreciated.
The working combination for this case is:
dataSources:
{
"name": "BuildNames",
"endpointUrl": "{{endpoint.url}}/api/build",
"resultSelector": "jsonpath:$.builds[*]"
}
dataSourceBindings:
{
"target": "definition",
"dataSourceName": "BuildNames",
"resultTemplate": "{ \"Value\" : \"{{{uri}}}\", \"DisplayValue\" : \"{{{uri}}}\" }"
}

Write initial settings to settings.json

I am looking for a way to write initial settings to settings.json for when my extension is installed.
I found WorkspaceConfiguration API, but that seems to retrieving/updating values at runtime.
I'm looking to get my settings + comments into the default settings file
e.g. How TSLint does it:
I hope I get your question correctly: I assume you mean the User Settings settings.json you can get via File>Preferences>User Settings.
If you know that TSLint does it, you can go to your extensions folder (windows: $USERFOLDER/.vscode/extensions), pick the extension (in my case it was the folder "eg2.tslint-0.6.7") and peek the files.
...
"contributes": {
"configuration": {
"type": "object",
"title": "TSLint",
"properties": {
"tslint.enable": {
"type": "boolean",
"default": true,
"description": "Control whether tslint is enabled for TypeScript files or not."
},
"tslint.rulesDirectory": {
"type": [
"string",
"array"
],
"items": {
"type": "string"
},
"description": "An additional rules directory",
"default": ""
},
"tslint.validateWithDefaultConfig": {
"type": "boolean",
"description": "Validate a file when there is only a default tslint configuration is found",
"default": false
},
"tslint.configFile": {
"type": "string",
"description": "The path to the rules configuration file",
"default": ""
},
"tslint.ignoreDefinitionFiles": {
"type": "boolean",
"default": true,
"description": "Control if TypeScript definition files should be ignored"
},
"tslint.exclude": {
"type": [
"string",
"array"
],
"items": {
"type": "string"
},
"description": "Configure glob patterns of file paths to exclude from linting"
},
"tslint.run": {
"type": "string",
"enum": [
"onSave",
"onType"
],
"default": "onType",
"description": "Run the linter on save (onSave) or on type (onType)"
},
"tslint.nodePath": {
"type": "string",
"default": "",
"description": "A path added to NODE_PATH when resolving the tslint module."
},
"tslint.autoFixOnSave": {
"type": "boolean",
"default": false,
"description": "Turns auto fix on save on or off."
}
}
}
...
Hope this helps