Devops Release pipelines
When you work with LCS then below list of data base movement operations are familiar to you. Nowadays exporting and refreshing can also be triggered with the Database Movement API This can become extremely handy for daily automated backups of D365FO databases. How we do it? With DEVOPS release pipelines. The pipeline looks like this. The BACKUP TST is disabled because the API does not ‘yet’ support Tier 1 Databases.
Speeding up
Because we had to apply automated backups of D365FO databases at multiple customers. It became time consuming. So, we optimized it. All customer specific setting became Variables of the pipeline. Because customer specific Client ID, Client Secret, and password, are sensitive information we have hidden them. Be aware in case you unhide, the values are cleared.
PowerShell
Below PowerShell script is a sample of how we generate the Token. This token is later used on the backup commands PowerShell.
$tokenUrl = “https://login.microsoftonline.com/common/oauth2/token”
$tokenBody = @{
grant_type = “password”
client_id = “$(CLIENTID)”
client_secret = “$(CLIENTSECRET)”
resource = “https://lcsapi.lcs.dynamics.com”
username = “$(USERNAME)”
password = “$(PASSWORD)”
}
$tokenResponse = Invoke-RestMethod -Method ‘POST’ -Uri $tokenUrl -Body $tokenBody
$token = $tokenResponse.access_token
Write-Host “##vso[task.setvariable variable=TOKEN] $token”
In the next sample we create the backup
$cstzone = [System.TimeZoneInfo]:ConvertTimeBySystemTimeZoneId( (Get-Date), ‘W. Europe Standard Time’)
$filedate = Get-Date $cstzone -f “yyy-MM-dd”
$BackupName = “ACC-$filedate”
Write-Output $BackupName
$refreshUrl = “https://lcsapi.lcs.dynamics.com/databasemovement/v1/export/project/$(LCSPRPOJID)/environment/$(ACC)/backupName/$BackupName”
$refreshHeader = @{
Authorization = “Bearer $(TOKEN)”
“x-ms-version” = ‘2017-09-15’
“Content-Type” = “application/json”
}
$refreshResponse = Invoke-RestMethod $refreshUrl -Method ‘POST’ -Headers $refreshHeader
Write-Output $refreshResponse
And the DEVOPS insider will comment, yeah dream on, no build , is also no release. True, you just must reuse a build pool in your environment.
Please be aware that MS is throttling these requests, only 3 backups a day are possible. And at the end, we generate an email notification for the people that really need it.
LCS
We do not use the alerts from LCS, it causes simply too many emails. So, we disable the next notification for all LCS users