Create task in TFS via PowerShell - powershell

I need to create a task in TFS with PowerShell
I used the VSTeam (A PowerShell module for many features in TFS / Azure DevOps). The item is created. I have a template for the description but i don't know how to insert it to -Description that gets a string
Here is an example of the template:
The build is an hyper link and also the tfs item (patch XXXX)
How can I built the string like this? How to create a link for items?
How to set a bold string?
Can I copy a link from TFS?
There is a new build. The build location:
\\XXXXX\global\QA\
The patches that were added:
Patch 1269263: "Title"
Patch 1271540: "Title"

Have you looked into VSTeam? A PowerShell module for many features in TFS / Azure DevOps.
Set-VSTeamAccount -Account http://localtfs:8080/tfs/DefaultCollection -UseWindowsAuthentication
Set-VSTeamDefaultProject Demo
$additionalFields = #{"System.Tags"= "TestTag"; "System.AreaPath" = "Project\\MyPath"}
Add-VSTeamWorkItem -Title "New Work Item" -WorkItemType Task -AdditionalFields $additionalFields
ID Title Status
-- ----- ------
6 New Work Item To Do
The description field in TFS/Azure DevOps contains HTML text. Any formatting can be done using standard HTML constructs. <i> for italic, <b> for bold <a href="https://....."> for links.
To get the links you may need to invoke other REST APIs to get the build details. Most APE results have a links collection with a web link you can use to direct people to the web page for that thing.
Example from a Build/GET API call:
GET https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/builds/2817
{
"_links": {
"self": {
"href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/Builds/2817"
},
"web": {
"href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_build/results?buildId=2817"
},
"sourceVersionDisplayUri": {
"href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/builds/2817/sources"
},
"timeline": {
"href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/builds/2817/Timeline"
},
"badge": {
"href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/status/36"
}
},
...
...
}
In this case self is the link that retrieved this document. web is the equivalent in the WebUI, etc.
You'll find that other elements returned by the API carry a url property. By folliwing that URL, you'll get the _links collection for that object as well:
...
...
"project": {
"id": "a88536a2-a889-45a3-a955-ddf1af8aeba1",
"name": "azure-devops-extensions",
"description": "This projects hosts the pipelines for all my Azure DevOps marketplace extensions.",
"url": "https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1",
"state": "wellFormed",
"revision": 414360082,
"visibility": "public",
"lastUpdateTime": "2019-06-28T09:48:16.943Z"
},
Following:
GET https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1
{
"id": "a88536a2-a889-45a3-a955-ddf1af8aeba1",
"name": "azure-devops-extensions",
"description": "This projects hosts the pipelines for all my Azure DevOps marketplace extensions.",
"url": "https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1",
"state": "wellFormed",
"revision": 414360082,
"_links": {
"self": {
"href": "https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1"
},
"collection": {
"href": "https://dev.azure.com/jessehouwing/_apis/projectCollections/6ac92044-9ce2-40d0-b882-f6b6648dff8b"
},
"web": {
"href": "https://dev.azure.com/jessehouwing/azure-devops-extensions"
}
},
"visibility": "public",
"defaultTeam": {
"id": "7edc4d0a-3d22-44ee-a6cd-96a3dbf0690f",
"name": "azure-devops-extensions Team",
"url": "https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1/teams/7edc4d0a-3d22-44ee-a6cd-96a3dbf0690f"
},
"lastUpdateTime": "2019-06-28T09:48:16.943Z"
}
This way you can collect the links to the appropriate UI pages to direct your users to.

Related

Add files to Salesforce CMS channel folder via Connect API?

I'm developing an integration that will programmatically create product entries in Salesforce, and part of that process needs to be the addition of product images. I'm using the Connect API and am able to make a GET call to the right folder like this (I've scrambled the IDs and what not for this example):
https://example.salesforce.com/services/data/v52.0/connect/cms/delivery/channels/0591G0000000006/contents/query?folderId=9Pu1M000000fxUMSYI
That returns a payload like this:
{
"currentPageUrl": "/services/data/v52.0/connect/cms/delivery/channels/0ap1G0000000006/contents/query?page=0&pageSize=250",
"items": [
{
"contentKey": "MCZ2YVCGLNSBETNIG5P5QMIS4KNA",
"contentNodes": {
"source": {
"fileName": "PET Round.jpg",
"isExternal": false,
"mediaType": "Image",
"mimeType": "image/jpeg",
"nodeType": "MediaSource",
"referenceId": "05T0R000005MthL",
"resourceUrl": "/services/data/v52.0/connect/cms/delivery/channels/0ap1G0000000007/media/MCY2YVCGLNSBETNIG5P4QMIS4KNA/content",
"unauthenticatedUrl": "/cms/delivery/media/MCZ2YVCGLNSBETNIG5P4QMIS4KNA",
"url": "/cms/delivery/media/MCY2YVCGLNSBETNIG5P4QMIS4KNA"
},
"title": {
"nodeType": "NameField",
"value": "844333"
}
},
"contentUrlName": "844333",
"language": "en_US",
"managedContentId": "20T0R0000008U9qUAE",
"publishedDate": "2021-08-18T16:20:57.000Z",
"title": "844333",
"type": "cms_image",
"typeLabel": "Image",
"unauthenticatedUrl": "/cms/delivery/v52.0/0DB1G0000008tfOWAU/contents/20Y0R0000008y9qUAE?oid=00D0R000000OI7GUAW"
}
]
}
I am also able to retrieve images by contentKey with a GET call like this:
https://example.salesforce.com/services/data/v52.0/connect/cms/delivery/channels/0ap1G0000000007/media/MCZ2ZVCGLNSBETMIG5P4QMIS4KNA/content
Anyone know what the endpoint should look like and what parameters etc it should have? I'm having trouble finding anything for this specific scenario in the docs but surely there's a way.
Thanks!

Azure Devops rest API for create pipeline with source provider bitbucket not working

I am new on Azure and trying to create pipeline through rest api with below URL
https://dev.azure.com/my-org/my_project/_apis/pipelines?api-version=6.1-preview.1
When Source Provider is Azure Git Repo then it working perfectly fine with below request body
{
"folder": "\\",
"name": "Test-Pipeline-1",
"configuration": {
"type": "yaml",
"path":"/azure-pipelines.yml",
"repository":{
"id": "1f13f61c-eade-b36bc515bb5e",
"name": "TestAzure123",
"type":"azureReposGit"
}
}
}
But when Source Provider is Bitbucket Cloud then its not working
{
"folder": "\\",
"name": "Bitbucket-Pipeline",
"configuration": {
"type": "yaml",
"path":"/master-pipeline.yaml",
"repository": {
"id": "sid_07/Bitbucket-repository",
"name": "Bitbucket-repository",
"type": "Bitbucket"
}
}
}
I am getting below exception
{
"$id": "1",
"innerException": null,
"message": "This API does not support creating pipelines with repositories of type Unknown.",
"typeName": "Microsoft.Azure.Pipelines.WebApi.UnsupportedRepositoryTypeException, Microsoft.Azure.Pipelines.WebApi",
"typeKey": "UnsupportedRepositoryTypeException",
"errorCode": 0,
"eventId": 3000
}
Is pipeline creation supported through rest api for bitbucket? or am I missing something? Please help
I have already taken reference from similar issue
https://developercommunity.visualstudio.com/content/problem/1101376/create-pipeline-rest-api-does-not-work.html
Azure Devops rest API for create pipeline with source provider bitbucket not working
I am afraid the REST API Pipelines - Create does not support the creation of a pipeline whose source type is bitbucket at this moment.
When I use the request body below, which I used to create a pipeline for the resource type of github:
{
"folder": "\\",
"name": "Test-Pipeline-2",
"configuration": {
"path": "TestDemo.yml",
"repository": {
"fullName": "xxx/leotest",
"connection": {
"id": "e11d299a-0bfd-4a38-a77c-xxxxxxxx"
},
"type": "bitbucket"
},
"type": "yaml"
}
I got the same error as you:
Then I created that pipeline manually, and use the REST API Pipelines - Get to get the detailed info about this pipeline, I got following info:
"configuration": {
"path": "BitbucketRepo.yml",
"repository": null,
"type": "yaml"
},
"url": "https://dev.azure.com/xxx/xxxxx/_apis/pipelines/146?revision=2",
"id": 146,
"revision": 2,
"name": "BitbucketRepo",
"folder": "\\YAML\\Resources"
We could to know the part of repository: is null.
So, the REST API Pipelines - Create does not support create pipeline with source provider bitbucket at this moment.
For this request, you could add it for this feature on our UserVoice site (https://developercommunity.visualstudio.com/content/idea/post.html?space=21 ), which is our main forum for product suggestions. Thank you for helping us build a better Azure DevOps.

Add/remove pipeline checks using REST API

I have a requirement to dynamically add/remove or enable disable approval and checks at azure DevOps pipeline environment.
Is there a rest api for this?
Is there a rest api for this?
Yes, it has. BUT, as what the #Krysztof said, we haven't provide such api documents to public as of today. This is because what you are looking for is one feature (configure Check and approval from environments ) that only support for YAML pipeline, and until now, we are developing but does not publish the corresponding rest api (for YAML) docs.
But, as work around, you can catch these apis from F12. Just do action from UI, then capture and analyze corresponds api records to found out what you are expecting.
Here I make the summary to you.
The api that used to add/delete approval and check to environment is:
https://dev.azure.com/{org name}/{project name}/_apis/pipelines/checks/configurations
The corresponding api method for add or delete is Post and DELETE.
Firstly, share you the request body samples which for approval and check added.
1) Add approval to this environment:
{
"type": {
"id": "8C6F20A7-A545-4486-9777-F762FAFE0D4D", // The fixed value for Approval
"name": "Approval"
},
"settings": {
"approvers": [
{
"id": "f3c88b9a-b49f-4126-a4fe-3c99ecbf6303" // User Id
}
],
"executionOrder": 1,
"instructions": "",
"blockedApprovers": [],
"minRequiredApprovers": 0,
"requesterCannotBeApprover": false // The pipeline requester allow to approve it.
},
"resource": {
"type": "environment",
"id": "1", // Environment id
"name": "Deployment" //Environment name
},
"timeout": 43200 // Set the available time(30d) of this approval pending. The measure unit is seconds.
}
2) Add task check, Azure function, Invoke rest api task and etc:
{
"type": {
"id": "fe1de3ee-a436-41b4-bb20-f6eb4cb879a7", // Fixed value if you want to add task check
"name": "Task Check" //Fixed value
},
"settings": {
"definitionRef": {
"id": "537fdb7a-a601-4537-aa70-92645a2b5ce4", //task Id
"name": "AzureFunction", //task name
"version": "1.0.10" //task version
},
"displayName": "Invoke Azure Function", //task display name configured
"inputs": {
"method": "POST",
"waitForCompletion": "false",
"function": "csdgsdgsa",
"key": "436467543756" // These are all task inputs
},
"retryInterval": 5, // The re-try time specified.
"linkedVariableGroup": "AzKeyGroup"// The variable group name this task linked with
},
"resource": {
"type": "environment",
"id": "2",
"name": "Development"
},
"timeout": 43200
}
In this request body, you can find the corresponding task id from our public source code. Just check the task.json file of corresponding task.
3) Add template check:
{
"type": {
"id": "4020E66E-B0F3-47E1-BC88-48F3CC59B5F3", // Fixed value for template check added.
"name": "ExtendsCheck" //Fixed value
},
"settings": {
"extendsChecks": [
{
"repositoryType": "git", // github for Github source, bitbucket for Bitbucket source
"repositoryName": "MonnoPro",
"repositoryRef": "refs/heads/master",
"templatePath": "tem.yml"
}
]
},
"resource": {
"type": "environment",
"id": "6",
"name": "development"
}
}
In this body, if the template source is coming from github or bitbucket, the value of repositoryName should like {org name}/{repos name}.
Hope these are helps.
This is an older question but we had a similar need. There does not appear to be a direct API To query this, but this GitHub Project pointed us in the right direction:
# GET ENVIRONMENT CHECKS (stored under .fps.dataProviders.data['ms.vss-pipelinechecks.checks-data-provider'].checkConfigurationDataList)
GET https://dev.azure.com/{{organization}}/{{project}}/_environments/{{environment_id}}/checks?__rt=fps&__ver=2
As mentioned above under .fps.dataProviders.data['ms.vss-pipelinechecks.checks-data-provider'].checkConfigurationDataList the list of who is authorized is provided.
The officially documented APIs can tell you that there are checks in place; for example:
GET https://dev.azure.com/{organization}/{project}/_apis/pipelines/checks/configurations?resourceType=environment&resourceId={id}
Can tell you that you have checks enabled (including an Approval check) but this isn't super useful as it does not give a list of who can Approve.
Note that you can get the list of environments (to get their resource ID) using this documented API:
GET https://dev.azure.com/{organization}/{project}/_apis/distributedtask/environments?api-version=7.1-preview.1
This is not supported at the moment. You can upvote feature request to show your interest here.

Where can I find System.TeamProjectId for a project in Azure Devops

I need this Id upfront but I can't seem to find it anywhere online?
The documentation only refers to it as a system variable.
Context:
I have multiple projects and I want to identify a project during CI so it can run a powershell script hosted in another repository.
You can get the all team projects id with REST Api:
https://dev.azure.com/{organization}/_apis/projects?api-version=5.0-preview.3
Results:
{
"count": 3,
"value": [
{
"id": "eb6e4656-77fc-42a1-9181-4c6d8e9da5d1",
"name": "Fabrikam-Fiber-TFVC",
"description": "Team Foundation Version Control projects.",
"url": "https://dev.azure.com/fabrikam/_apis/projects/eb6e4656-77fc-42a1-9181-4c6d8e9da5d1",
"state": "wellFormed"
},
{
"id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
"name": "Fabrikam-Fiber-Git",
"description": "Git projects",
"url": "https://dev.azure.com/fabrikam/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
"state": "wellFormed"
},
{
"id": "281f9a5b-af0d-49b4-a1df-fe6f5e5f84d0",
"name": "TestGit",
"url": "https://dev.azure.com/fabrikam/_apis/projects/281f9a5b-af0d-49b4-a1df-fe6f5e5f84d0",
"state": "wellFormed"
}
]
}
You don't even need use Postman or create Http request, just enter the API url above in the browser.
You can examine the HTML in the UI of the dashboard on your organisation projects page:

Add ARM Service Endpoint programatically in VSTS

I have an existing SPN in Azure AD and want to add to VSTS programatically.
Is this possible?
VSTS Rest-API? Examples?
Through powershell?
You can use the REST API to manage your endpoints.
For example the following POST will create an Azure endpoint:
https://fabrikam.visualstudio.com/DefaultAgileGitProject/_apis/serviceendpoint/endpoints?api-version=4.1-preview.1
{
"data": {
"SubscriptionId": "12345678-1234-1234-1234-123456129012",
"SubscriptionName": "TestSubscriptionName"
},
"id": "64be39c2-102b-416d-a3ac-2de40ebc8513",
"name": "TestEndpoint",
"type": "Azure",
"authorization": {
"parameters": {
"Certificate": "dummyCertificate"
},
"scheme": "Certificate"
},
"isReady": false
}
You can find the full documentation here: https://learn.microsoft.com/en-us/rest/api/vsts/serviceendpoint/endpoints/create?view=vsts-rest-4.1