I have a two stage release:
Stage 1 creates a test DB
pre-deploy approval on Stage 2
Stage 2 test DB just created is destroyed
This setup allows devs time to test changes before approving automated cleanup.
My question is, is it possible to dynamically set the pre-deploy approval (step #2 above) to the user who submitted the release? If not, perhaps there is a better way to pause the release until the submitter manually allows it to continue?
For this issue , you can try to set approver through the Definitions - Update rest api.
You can add approver in "preDeployApprovals" argument. For example:
"preDeployApprovals": {
"approvals": [{
"approver": {
"id": "9f723013-a332-64e5-aea9-6e3ebxxxxx",
"displayName": "hughl01",
"isContainer": false
},
"isAutomated": false,
"isNotificationOn": false,
"rank": 1,
"id": 0
}]
},
Then you can set the pre-deploy approval to the user who submitted the release through pre-defined variables:
Release.RequestedFor The display name of identity that triggered
the release.
Release.RequestedForId The ID of identity that triggered the
release.
In the request body ,you can use $(Release.RequestedFor) to dynamically get the name of the user who triggered the release and use it as the name of approver. The same goes for $(Release.RequestedForId).
Here are some references for you:
set approver with PowerShell
release pre-defined variables
Related
We have a bulk import mechanism where we add users to ADO and create tasks assigned to them using the user Entitlements API. We have observed that after initially adding the users to ADO, any tasks created for them via the API does not resolve the user's identity correctly. Any subsequent tasks are created correctly and show the users resolved.
Any task's 'Assigned To field should be an Identity -
Fname Lname alias#email.com
but for the first upload, it is just alias#email.com.
Is there a way to do this so that this works, even for first upload?
I have tested it in my side and I can assign the new user for the work item by api.
And you should check if the new account has the right permission.
These are my json test:
[
{
"op": "add",
"path": "/fields/System.Title",
"from": null,
"value": "xxx"
},
{
"op" : "add",
"path": "/fields/System.AssignedTo",
"from": null,
"value": "xxx#outlook.com"
}
]
I can use it under postman. Also, you could use the e-mail or user name under value.
Besides, you could share the used tool and the steps about your operation with us to help us troubleshoot your issue more quickly.
I want to assign required approvers based on who raises a PR and not what the PR is on.
I have a set of repos that is maintained by multiple teams. I want to have a team be automatically added as required reviewers based on the user making the PR.
Is this even possible?
Is this even possible?
It's possible. But the process would be very complex since Azure Devops doesn't have such out-of-box feature, so we have to use Build Validation/Rest API/PS to achieve what you want.
1.Create a Classic Build pipeline with PS task.
2.Add build validation in branch policy. So this pipeline will run first if anyone raises a PR.
3.If one pipeline is triggered by PR, we can access the variables like $(Build.Repository.ID),$(Build.RequestedFor)(the user making the PR),$(Build.RequestedForEmail)(the user's email). See predefined variables.
4.Use Teams-Get to get list of teams in current project. You now have the TeamIDs, you now know the corresponding TeamIDs the user belongs to.
5.Use powershell switch or if statement to dynamically define the team the user belongs to.
switch ("$(Build.RequestedFor)")
{
"User1" {$TeamID="xxxx"; Break}
"User2" {$TeamID="xxxx"; Break}
"User3" {$TeamID="xxxx"; Break}
Default {
"No matches"
}
}
6.Use Configurations-List to list the ConfigurationIDs in this project. (You may also need to determine the correct ConfigurationID by SourceRepo and SourceBranch)
7.Then use Configuration-Update to update the branch policy to define required approvers dynamically.
The request body would look like this:
{
"isEnabled": true,
"isBlocking": true,
"type": {
"id": "fd2167ab-b0be-447a-8ec8-39368250530e"
},
"settings": {
"requiredReviewerIds": [
"{replace it with corresponding TeamID}"
],
"filenamePatterns": [],
"addedFilesOnly": false,
"scope": [
{
"repositoryId": "{replace it with your repoID in step3}",
"refName": "refs/heads/master",
"matchKind": "exact"
}
]
}
}
You can do step5 and step7 in same PS task.
We have an Azure pipeline building a static site. When there is a change in a content repository the site needs to be rebuilt. For that, we're using webhooks and Azure DevOps API. The request to queue the build is very simple and is illustrated for example here.
What I don't like about this is that int the build listing it says "Manually triggered for person XY", where the person XY is the one who generated the credentials used in the API request. It seems quite confusing because any API request seems strange to be labeled as "manually requested". What would be the best way how to achieve more semantically correct message?
I've found there is a reason property which can be sent in the request. But none of the values seems to represent what I want and some of them do not work (probably need additional properties and there is no documentation for that).
Based on my test, when you use the Rest API to queue a build and set the build reason, the reason could be shown in the Build(except:batchedCI and buildCompletion).
Here is the Rest API example:
Post https://dev.azure.com/Organization/Project/_apis/build/builds?api-version=4.1
Request Body:
{
"definition": {
"id": 372
},
"reason":"pullRequest"
}
The value : checkInShelveset individualCI pullRequest schedule could show their own names.
The value: manual and none could show manually trigger.
The other value(e.g. All, userCreated) will show Other Build Reason.
For the value: batchedCI and buildCompletion.
BatchedCI: Continuous integration (CI) triggered by a Git push or a TFVC check-in, and the Batch changes was selected.
This means that batch changes are required to achieve this trigger. So it doesn't support to queue build in Rest API .
buildCompletion: you could refer to this ticket This reason doesn't support in Rest API-queue Build.
Note: If you enter a custom value or misspelling, it will always display manual trigger.
In the end, I went with all value and also overriding the person via requestedFor property. This leads to the message "Other build reason", which seems usable to me.
{
"definition": {
"id": 17
},
"reason":"all",
"requestedFor": {
"id": "4f9ff423-0e0d-4bfb-9f6b-e76d2e9cd3ae"
}
}
However, I'm not sure if there aren't any unwanted consequences of this "All reasons" value.
I am trying to integrate Servicenow with Azure Devops Board to create/update etc etc on a work item using REST APIs
I was successful in creating and updating lot of things on the workitems
I am not able to find an API which tells the workitem to fall in a specific Swimlane
If you look in to the image I have attached, which has a default swimlane(test) and custom ones... so H have an api which moves it from "ToDo" to "Doing", but if you notice there multiple "Doing" as there are different swimlanes, so can anyone please help what the trick is or an API which tells the workitem to fall in a specific SwimLane
I did some research and found "System.BoardLane" I did use that in post and patch
ERROR:
{
"$id": "1",
"customProperties": {
"ReferenceName": null
},
"innerException": null,
"message": "TF401326: Invalid field status 'ReadOnly' for field 'System.BoardLane'.",
"typeName": "Microsoft.TeamFoundation.WorkItemTracking.Server.WorkItemFieldInvalidException, Microsoft.TeamFoundation.WorkItemTracking.Server",
"typeKey": "WorkItemFieldInvalidException",
"errorCode": 600171,
"eventId": 3200
}
then I used operation "op" :"move"
ERROR:
{
"$id": "1",
"innerException": null,
"message": "Move/Copy is not implemented.",
"typeName": "Microsoft.VisualStudio.Services.WebApi.Patch.PatchOperationFailedException, Microsoft.VisualStudio.Services.WebApi",
"typeKey": "PatchOperationFailedException",
"errorCode": 0,
"eventId": 3000
}
Azure DevOps REST APIs FOR SWIMLANE
In fact, you were very close to the correct answer.
The first error you faced: TF401326: Invalid field status 'ReadOnly' for field 'System.BoardLane' has indicate that if you want to modify the SwimLane by updating the System.BoardLane field via API, we does not allow that because of its read-only.
(For those fields, not only System.BoardLane is read-only, but also the System.BoardColumn)
This is by designed.
In order to update the SwimLane, here you need to update the extension fields instead of System fields via the API.
Step1:
Call the Get - Boards API to get the information about the Board. In its response body, the extension field names will display under fields -> rowField.
Sample:
GET https://dev.azure.com/{org name}/{project name}/{team name}/_apis/work/boards/Stories?api-version=5.1
The reference names for these extension fields will include a GUID that is unique for the board(e.g. WEF_6623ED31B8E04C778FB1129D3239B1A7_Kanban.Lane).
Step2:
Call the Update - Work Items API, using the field names you got above as the path (e.g. /fields/WEF_6623ED31B8E04C778FB1129D3239B1A7_Kanban.Lane) and input the lane value as the name of the row you want to move the item into:
Sample:
PATCH https://dev.azure.com/{org name}/{project name}/_apis/wit/workitems/{WIT id}?api-version=5.1
Request body:
[
{
"op": "add",
"path": "/fields/WEF_6623ED31B8E04C778FB1129D3239B1A7_Kanban.Lane",
"from": null,
"value": "Lane for product team"
}
]
Lane for product team is one of the Swimlane.
Now, you would see that the work item moved into the corresponding lane you specified.
Note: The GUID of the extension fields is unique for the board. Different boards has different extension fileds GUID value.
The swimlane that is used is based on the status of the workitem (I believe the field you want is System.Status) If you update that value of the workitem, it should move the workitem into the appropriate swimlane.
You can configure your team's board settings to map statuses to the swim lanes you want. If you are using an standard board process, then it should be pretty straightforward mapping between statuses and swim lanes, but if you have customized work items you will need to apply that logic to your code(IE this new item should be in a status of X to show as doing)
I came around this API to create a release.
But there seems to be no property in the request body where I can specific a certain stage to be released?
Is there another way I can do it?
First of all, you need to create the release with the API you provided, after that, you need to use the Update Release Environment API to start the stage (environment = stage):
PATCH https://vsrm.dev.azure.com/{organization}/{project}/_apis/Release/releases/{releaseId}/environments/{environmentId}?api-version=5.1-preview.6
Body:
{
"status": "inProgress",
"scheduledDeploymentTime": null,
"comment": null,
"variables": {}
}