Practical way to automate hourly releases on VSTS - azure-devops

We would like to trigger two of our pipelines hourly. How can we do that other than this part as we want to implement business rules such as do not run if there is an active deployment?

If you want hourly deployments, you'll need to create 24 schedules for each hour and then use the deployment queue setting. You can set the deployment queue settings to a max number of parallel deployments to 1.
For more information check this link

Related

How to fetch all the deployments completed after the given timestamp using Azure Devops REST Api?

So there is List Release Deployments API. It allows to get all the deployments started after the given timestamp. However, how to get those completed after it?
Rationale
Suppose I want to write a scheduled job that fetches information about completed deployments and pushes it to an Azure Application Insights bucket (for example for DORA metrics). I do not understand how it can be done easily without the ability to filter by the completion date. A relatively hard way would be to fetch by the started date, notice all the deployments inProgress or notDeployed and record them in a dedicated database. Then on the next polling cycle fetch new deployments and all those still recorded in the aforementioned database. This is much more complicated than it could have been with the ability to filter by the completion date.
Am I missing anything here? Maybe there is a simpler way (possibly using another API) that I just do not see?
EDIT 1
By the way, the hard way is even harder than I thought, since apparently there is no way to fetch release deployments by their Id.
EDIT 2
The plot thickens. If a stage has post deployment approvals, then the stage is reported as inProgress, even though de facto it has already been deployed. So an API that just filters by completion date would omit such deployments. It has to be with an option to include such deployments.

Can a Self Hosted Agent be set as enabled at certain times?

In Azure DevOps, can an agent be set as enabled or disabled at certain times? This is with self-hosted agents. I know there is the toggle in the UI to turn agents on at off as in the screenshot below. But can the enable and disable be scheduled? I'd like to add a user's machine at the weekend for example to help speed up the tests that are run, but obviously we don't want it running tests while in use Monday to Friday.
There's no option to enable/disable agents by schedule. However, you can try to achieve a similar effect with this approach:
Author a new pipeline with a single agentless job. It can invoke the Azure DevOps REST API to change the status of the agent (enabled/disabled). You can find this answer useful as a starting point.
Define the scheduled trigger the way you'd like your agent to be enabled/disabled.

How to (properly) Create Jobs On Demand

What I would like to do
I would like to create a Kubernetes workflow where users could POST jobs whenever they wanted, and they might do it at any time, not necessarily scheduling anything (CronJobs), or specifying parallelism or completion requirements, i.e., users could create Jobs on demand.
How I would do it right now
The way I'm thinking about accomplishing this is by simply applying the Jobs to the Kubernetes cluster (I also have to make sure the job doesn't have the same name of a current one because otherwise Kubernetes will think it's a mistake and won't create another one). However, this feels improper because the Jobs will be kind of scattered on the cluster and I would lose control over them (though Kubernetes would supposedly automatically manage them optimally).
Is there a better, proper a way?
I imagine a more proper way of configuring all this is to create some sort of Deployment and Service on top of the Jobs, but is that an existing feature on Kubernetes? Huge companies probably have had this problem in the past so I wonder: what are the best practices for this Kubernetes Jobs On Demand use case?
Not a full answer but you might be interested in this project: https://github.com/ivoscc/kubernetes-task-runner.
It provides an API to launch one-time tasks as Jobs on a Kubernetes cluster, handles input/output files via GCS and periodically cleans up finished Jobs.

Azure DevOps - schedule release deployment is not available

In Azure DevOps you can schedule a release as many times as possible. In my example, I want to create a release 3 times a day Monday - Friday
But, if I need to actually deploy those releases 3 times a day Monday - Friday, I can't. There is only one slot available and user can't add more.
Is this a limitation of Azure DevOps and how I can actually deploy my release (not create them) 3 times a day?
This is not available at present.
Not sure if totally got your point, what you are looking for is something similar to schedule redeploy.
When you submit a pre-deployment approval for a stage, you can defer the deployment until a specified time. You could not select or specify multiple times here.
You could submit a feature request in Develop Community: https://developercommunity.visualstudio.com/spaces/21/index.html
As Patrick pointed out, this currently isn't possible. You can set multiple schedules for a release but individual stages can't be scheduled more than once. As a workaround, you could clone the stage and then set different schedules for it.

Is it possible to combine a gate and an approval to limit an Azure deployment?

In Azure, you can limit deployments with gates and approvals. Gates are usually some sort of status or health check. Approvals require a certain user or group to manually approve the deployment.
Is it possible to combine the two?
For example, I'd like for a deployment to require an approval but only if it's before 8 am or after 5 pm.
Another example would be to require an approval if the application is not live (liveness would be determined by a REST call).
No there is no way to create "conditional approvals" this way. You can schedule Gates and/or approvals but can't make one dependent on the other. The only thing you can configure is to ignore the gate and still ask for approvals or ask for approvals and then run the gates.
But what you can, using a custom release gate (Azure Function for example), is to do the required check and then use the Azure DevOps REST API to edit the release instance. An azure function with the right permissions could either enable or disable the approvers on the environment or override an approval.
An example of how to do this can be found here:
https://abelsquidhead.com/index.php/2017/12/25/creating-async-custom-automated-release-gates-in-vsts-with-rest-api/
https://github.com/Microsoft/azure-pipelines-tasks/blob/master/docs/authoring/gates.md
https://github.com/Microsoft/azure-pipelines-extensions/tree/master/ServerTaskHelper/DistributedTask.ServerTask.Remote.Common