Can I restore a deleted Task Group in Azure Devops (VSTS)? - azure-devops

I accidentally deleted a Task Group but I need it and I would like to restore it.
Is there any way that a deleted Task Group could be restored in Azure DevOps (VSTS)?
I see in the documentation that deleted Build Definitions can be restored but I found nothing about deleted Task Groups.

There is certainly a workaround to restore the task group, and that is creating an identical one and replacing all the references to point to the newly created task group.
For that, first you need the GUID of the deleted task group.
You can get it easily from a pipeline referencing it:
missingTaskGroup
Just go to the history tab of the given pipeline and look for the deleted task group and its GUID in the YAML after opening one of the versions using "Compare Difference".
You should find something like this, where id is the GUID of the task group:
"steps": [
{
"environment": {},
"enabled": true,
"continueOnError": true,
"alwaysRun": true,
"displayName": "Task group: testTaskGroup ",
"timeoutInMinutes": 0,
"condition": "succeededOrFailed()",
"task": {
"id": "5e417q45-afea-4f74-a126-a26ea17020dc",
"versionSpec": "1.*",
"definitionType": "metaTask"
},
"inputs": {}
}
Replacing the placeholders in the following URL and navigating to it should let you retrieve the full history of the deleted task group:
https://dev.azure.com/[yourOrganization]/[yourProject]/_taskgroup/[taskGroupGuid]
After switching to the History tab, you can just save the JSON of the version you prefer and use the Import feature in the Taskgroups page to create a new, but identical task group as the deleted one.

Please be aware that currently the suggested answer no longer works. After deleteing a taksgroup and hitting the URL the history tab yields nothing, and the export feature does not work.
Based on the documentation below, there is no restore method.
https://learn.microsoft.com/en-us/rest/api/azure/devops/distributedtask/taskgroups?view=azure-devops-rest-5.1

Related

How to be notified about a deployment done in YAML pipelines using Azure DevOps Service Hooks?

I'm posting this question to share my investigation about this issue and to ask for help in case anyone found something interesting.
Context
We are using Service Hooks with classic release pipeline for various purposes. We use Service Hooks trigger on event Release deployment completed. It's was very easy to setup.
When triggered by Azure DevOps, those events are stored for use in an external system. In this external system, we use Azure DevOps REST API to retrieve all the information we need.
Issue
Since YAML pipelines were released in GA, they are slowly replacing our classic release pipelines and we noticed that the existing Service Hooks were not longer triggered for YAML pipelines.
After some investigation, I discovered that those YAML pipelines doesn't trigger existing Release deployment completed events.
Instead, there is a new publisher named pipelines that contains new events that are triggered for YAML pipelines.
You can use the REST API to get all those events :
GET https://dev.azure.com/{{organization}}/_apis/hooks/publishers/pipelines?api-version=6.1-preview.1
Only 2 events looks promising for our needs here:
Run stage state changed: A new stage has started, or a stage has transitioned to canceling, canceled, failed, partially succeeded or succeeded
Run state changed: A new run has started, or a run has transitioned to canceling, canceled, failed, partially succeeded or succeeded
Those events are triggered for ALL pipelines: YAML, classic build and release.
Looking into those new events
Now I have found interesting events, we need to find a way to detect a deployment done using a deployment job in a YAML pipeline (released in GA last year).
I'm digging to discover what I can get from them. First step is to setup a new Service Hook with those new events, run a pipeline and get the payload sent when the event is triggered.
Here is a sample payload from the event stage-state-changed-event :
{
"id": "37f42f2c-3061-4c0a-a0ff-e67d235ecfec",
"eventType": "ms.vss-pipelines.stage-state-changed-event",
"publisherId": "pipelines",
"message": {
"text": "Run 1.21.027.2 stage DeployStage running.",
"html": "Run 1.21.027.2 stage DeployStage running.",
"markdown": "Run 1.21.027.2 stage [DeployStage](https://dev.azure.com/yourorganizationhere/19d42179-19ab-4242-aa1c-3f8e533daaaa/_build/results?buildId=248532) running."
},
"detailedMessage": {
"text": "Run 1.21.027.2 stage DeployStage running.",
"html": "Run 1.21.027.2 stage DeployStage running.",
"markdown": "Run 1.21.027.2 stage [DeployStage](https://dev.azure.com/yourorganizationhere/19d42179-19ab-4242-aa1c-3f8e533daaaa/_build/results?buildId=248532) running."
},
"resource": {
"stage": {
"_links": {
"web": {
"href": "https://dev.azure.com/yourorganizationhere/19d42179-19ab-4242-aa1c-3f8e533daaaa/_build/results?buildId=248532"
},
"pipeline.web": {
"href": "https://dev.azure.com/yourorganizationhere/19d42179-19ab-4242-aa1c-3f8e533daaaa/_build/definition?definitionId=1545"
}
},
"id": "6884a131-87da-5381-61f3-d7acc3b91d76",
"name": "DeployStage",
"displayName": "DeployStage stage",
"state": "running"
},
"run": {
"id": 248532,
"name": "1.21.027.2"
},
"pipeline": {
"url": "https://dev.azure.com/yourorganizationhere/19d42179-19ab-4242-aa1c-3f8e533daaaa/_apis/pipelines/1545?revision=9",
"id": 1545,
"revision": 9,
"name": "Pipeline Definition Name Here",
"folder": "\\"
},
"runId": 248532,
"stageName": "DeployStage",
"runUrl": "https://dev.azure.com/yourorganizationhere/19d42179-19ab-4242-aa1c-3f8e533daaaa/_apis/pipelines/1545/runs/248532"
},
"resourceVersion": "5.1-preview.1",
"createdDate": "2021-01-27T09:40:51.0986307Z"
}
As you can see, this payload contains only generic information. You have the stage name and the pipeline id and name.
Next step, trying to query REST API to get more information about the pipeline, run or stages.
A stage can contains multiple jobs and we are interested in a specific kind of job: deployment job.
Pipelines endpoints
⚠ Pipelines REST API endpoints are still in preview, you need to use version 6.1-preview.1.
I tried to get some information from those endpoints:
GET https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}?api-version=6.1-preview.1
GET https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs/{runId}?api-version=6.1-preview.1
GET https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs/{runId}/logs?api-version=6.1-preview.1
I didn't find anything useful in the data returned. No way to detect that the event triggered could be related to a deployment job done with a YAML pipeline.
Summarize
When using classic pipelines, it was easy to detect a deployment was completed using Service Hooks. I didn't find the equivalent for YAML pipelines.
Am I missing something ?
Or is this yet another feature that isn't available yet for YAML pipelines ?
Any idea how to track deployments done with YAML pipelines ?
Any help appreciated 🤗
Thank you for your time.
You are correct that the available event types for Pipelines are as below:
Run state changed
Run stage state changed
Run stage waiting for approval
Run stage approval completed
You can by default detect a stage state changed using Service Hooks only in a YAML pipeline. You could add a script task after the deployment, once the deployment succeeded send the message via API in the script to the service.

Automate Activity on Github to look good to potential employers

I want to automate daily activity on my github so that when a potential employer checks out my github they will see that I've been extremely active. Can anyone suggest the most simple way to do this that would look convicing?
One way you could achieve a daily automated GitHub update is to use the GitHub API to changes that are done automatically, either through a bash script, or some other way.
In a project, pick some files that will change all the time. That might be configuration file or just create a new file with something in it every day.
You can automate this part with a cron job. Make the cron job create/update a file every day at the same time.
Then using the GitHub v3 api, you can either create/update files and push them to your repo. Again, this can be part of your cron job.
By using this API, you'll get a commit from GitHub that should be reflected in your contributions chart on your profile.
If we see the response from GitHub, you should get something like this, which should count as a contribution.
{
"content": {
"name": "hello.txt",
"path": "notes/hello.txt",
"sha": "95b966ae1c166bd92f8ae7d1c313e738c731dfc3",
"size": 9,
"url": "https://api.github.com/repos/octocat/Hello-World/contents/notes/hello.txt",
.
.
.
},
"commit": {
"sha": "7638417db6d59f3c431d3e1f261cc637155684cd",
<more things>
"author": { <response here>
"committer": { <response here>
"message": "my commit message",
.
.
.
}

How do I resolve TF51005 for ReflectedWorkItemId when migrating Azure DevOps data?

i am trying to migrate a project from one organization project to another Project .
From Source Azure Devops Project to Target DEvops project.
What should be the ReflectedWorkItemIDFieldName: ?
i tried changing it to :
Custom.ReflectedWorkItemId
ReflectedWorkItemId
ProcessName.ReflectedWorkItemId
GlobalWit.ReflectedWorkItemId
but its does not helps. Please help me
error
Microsoft.TeamFoundation.WorkItemTracking.Client.ValidationException: TF51005: The query references a field that does not exist. The error is caused by «[Custom.ReflectedWorkItemId]»
===
my config file
"Source": {
"Collection": "https://dev.azure.com/somegDevOps/",
"Project": "ContosoAir",
"ReflectedWorkItemIDFieldName": "Custom.ReflectedWorkItemId",
"AllowCrossProjectLinking": false,
"PersonalAccessToken": "Intentionally removed"
},
"Target": {
"Collection": "https://dev.azure.com/ITIDEVOPSTEAM/",
"Project": "ContosoAir-Migrated",
"ReflectedWorkItemIDFieldName": "Custom.ReflectedWorkItemId",
"AllowCrossProjectLinking": false,
"PersonalAccessToken": "Intentionally removed"
},
To provide sync as well as migration it is important that the tools knows which items have already been migrated. This is the purpose of the ReflectedWorkItemId field.
This field needs to be added to the Target Project Work Items. If you are using "UpdateSourceReflectedWorkItemID" then it also needs to be added to the Source.
On both system the URL pointing to the migrated item on the other system is stored here. This means there is an easy way for a user to trace work items between the source and target systems (and vice versa).
How the ReflectedWorkItemId field is added depends on whether the system.
TFS / Azure DevOps Server [XML Process] - If you are using the classic XML process you will need to use https://learn.microsoft.com/en-us/azure/devops/reference/on-premises-xml-process-model?view=azure-devops-2019
Azure DevOps Service [XML Process] - If you use the Microsoft Migration tools to take your entire collection into Azure DevOps Service then you will need to download the XML zip, change the files, and reupload. https://learn.microsoft.com/en-us/azure/devops/migrate/migration-overview?view=azure-devops
Azure DevOps Service [Inherited Process] - you can customise and add the ReflectedWorkItemId
filed using the GUI. https://learn.microsoft.com/en-us/azure/devops/organizations/settings/work/manage-process?view=azure-devops

Azure DevOps Release changing appsettings.json Logging section

I have a problem regarding Azure DevOps and release management. First a little background - we use visualstudio.com along with build agents, release agents (running on different environment VMs) to manage our CI, builds, and releases. I am trying to troubleshoot logging on my non-development servers and have traced the problem back to missing elements in my appsettings.json file. When I log into my production VMs and look at the appsetings.json file, I found that my Logging section looked like this:
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Information"
}
},
While within my appsettings.json file within my build artifacts (the website .zip file) looks like this:
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
My logging issues are fixed when I go on the server and change the appsettings.json Logging section to match what is should be according to the appsettings in the build .zip.
My question is - what is it within the Azure DevOps release pipeline (formerly VSTS) that is changing the appsettings.json Logging section? I have verified that my release definition has no variable substitutions for the logging section.
This looks very much like your build is taking the wrong sources. Is it possible that the wrong appsettings.json that you're seeing reflects an outdated version? I don't know why this happens, but I've seen this a couple of times in the past both with Git and TFVC.
If this is the issue, then cleanup your agent working folders or select (once or permanantly) cleanup in the build definition:
Found the problem (and its a silly one). The problem ended being multiple declarations of the Logging section in the appsettings.json file. The declaration at the bottom of the file has:
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Information"
}
},
which would match whats getting deployed.

Why does Azure Automation store individual jobs in a deployment template, and can I remove them without damaging the deployment template?

I have schedules in Azure Automation that run a PowerShell script to remove batches of rows from Azure Table Storage. I was looking at using a deployment template to add schedules for other environments and noticed that I had a large number of JSON objects with a name like:
[parameters('jobs_7d50108e_270d_456a_04da_b79cbe13ba12_name')]
This appears to be an individual instance of an automation job, as I can see the individual schedule and runbook information. It doesn't appear to have much information in it:
{
"comments": "Generalized from resource: '/subscriptions/subscription-id/resourcegroups/resource-group/providers/Microsoft.Automation/automationAccounts/AutomationInstance/jobSchedules/job-schedule-id'.",
"type": "Microsoft.Automation/automationAccounts/jobSchedules",
"name": "[parameters('jobs_7d50108e_270d_456a_04da_b79cbe13ba12_name')]",
"apiVersion": "2015-10-31",
"properties": {
"runbook": {
"name": "MyRunBook"
},
"schedule": {
"name": "MySchedule"
},
"parameters": null
},
"resources": [],
"dependsOn": [
"[resourceId('Microsoft.Automation/automationAccounts', parameters('automationAccounts_AutomationInstance_name'))]"
]
}
Why is this being added to the deployment template (perhaps just for history)? Are there potentially bad effects if I remove them from the template?
A jobSchedule in Azure Automation is an association between a runbook and a schedule. Without a jobSchedule, the ARM template, when deployed, will set up any runbooks and schedules defined in the template, but without jobSchedules in the template, no runbooks will execute automatically based on those schedules.
The [parameters('jobs_7d50108e_270d_456a_04da_b79cbe13ba12_name')] line is just used to determine what the name of that jobSchedule will be, since every resource in ARM must be referenced by a name.