We have recently started using Azure DevOps Pipelines for our Dynamics 365 CRM implementation, but it is still new to me
I recently came across this blog post by Joe Griffin on how you can use PowerShell in Azure DevOps pipelines to ensure, that Access Team Templates works when deploying a solution - and I would like to use that.
However, I don't know where I add my parameters to script. Can I do that inline or do I need to add the script to my repo to do that? If so - how can I do that?
param(
#objectTypeCode: Unique Code that identifies the table in the environment for the Access Team Template. Always potentially different.
[Parameter(Mandatory=$true)]
[int]$objectTypeCode,
#atName: Name of the Access Team Template
[Parameter(Mandatory=$true)]
[String]$atName,
#accessRights: Number which represents the access rights defined for the template. Refer to this article for details on how to construct: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/accessrights?view=dynamics-ce-odata-9
[Parameter(Mandatory=$true)]
[int]$accessRights,
#d365URL: URL of the environment to connect to
[Parameter(Mandatory=$true)]
[String]$d365URL,
#clientID: AAD Client ID for the Application User linked to this environment
[Parameter(Mandatory=$true)]
[String]$clientID,
#clientSecret: AAD Client Secret for the Application User linked to this environment
[Parameter(Mandatory=$true)]
[String]$clientSecret
)
#Install dependencies
Install-Module Microsoft.Xrm.Data.PowerShell -Scope CurrentUser -Force
#Connect to the D365 environment
$conn = Connect-CrmOnline -ServerUrl $d365URL -ClientSecret $clientSecret -OAuthClientId $clientID -OAuthRedirectUri "http://localhost"
#We first attempt to retrieve the rows if they already exist, and update it accordingly; if this errors, then the row does not exist, so we need to create it instead
Write-Host "Processing Access Team Template for $atName..."
try
{
$atTemplate = Get-CrmRecord -conn $conn -EntityLogicalName teamtemplate -Id "44396647-CEDF-EB11-BACB-000D3A5810F2" -Fields teamtemplateid,teamtemplatename,objecttypecode,defaultaccessrightsmask,issystem
$atTemplateId = $atTemplate.teamtemplateid
Write-Host "Got existing Access Team Template row with ID $atTemplateId!"
$atTemplate.teamtemplatename = $atName
$atTemplate.objecttypecode = $objectTypeCode
$atTemplate.defaultaccessrightsmask = $accessRights
$atTemplate.issystem = 0
Set-CrmRecord -conn $conn -CrmRecord $atTemplate
Write-Host "Successfully updated Access Team Template row with ID $atTemplateId!"
}
catch [System.Management.Automation.RuntimeException]
{
Write-Host "Access Template row with ID $atTemplateId does not exist, creating..."
$atTemplateId = New-CrmRecord -conn $conn -EntityLogicalName teamtemplate `
-Fields @{"teamtemplateid"=[guid]"{44396647-CEDF-EB11-BACB-000D3A5810F2}";"teamtemplatename"=$atName;"objecttypecode"=$objectTypeCode;"defaultaccessrightsmask"=$accessRights;"issystem"=0}
Write-Host "Successfully created new Access Template row with ID $atTemplateId"
}
Write-Host "Script execution finished!"