Private/Configure-CICDEnvironment.ps1
function Invoke-ConfigureCICD { $adoRepo = $global:devops_gitRepo.Replace(' ', '') $adoOrg = $global:devops_projectFile.ADOOrgName $adoProject = $global:devops_projectFile.ADOProject $message = "Connecting to Power Platform" Write-Host $message do { $sel = Invoke-Menu -MenuTitle "---- Connecting to Power Platform ------" -MenuOptions "Continue", "Quit" } until ($sel -ge 0) if ($sel -eq 1) { exit } Install-XrmToolingPowerShell Write-Host $message Write-Host "" Write-Host "---- Enter the Credentials for your Deployment Staging (CI/CD) Environment ------" if (!$Credentials) { Do { $Credentials = Get-Credential -Message "Enter Credentials to Connect to D365 / Power Platform" } Until (($Credentials.GetNetworkCredential().UserName -ne "") -and ($Credentials.GetNetworkCredential().Password -ne "")) } if (!$username) { $username = $Credentials.GetNetworkCredential().UserName $password = $Credentials.GetNetworkCredential().Password } [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 $connCICD = Get-CrmOrganizations -OnLineType OAuth -Credential $Credentials $options = $connCICD | ForEach-Object {"$($_.FriendlyName) ($($_.WebApplicationUrl))"} do { $sel = Invoke-Menu -MenuTitle "---- Please Select your Deployment Staging (CI/CD) Environment ------" -MenuOptions $options $CICDEnvironment = $connCICD[$sel] } until ($CICDEnvironment -ne "") Write-Host $CICDEnvironment.WebApplicationUrl if (!$Credentials) { Do { $Credentials = Get-Credential -Message "Enter the Credentials the Pipeline should use for Deploying to D365 / CDS" } Until (($Credentials.GetNetworkCredential().UserName -ne "") -and ($Credentials.GetNetworkCredential().Password -ne "")) } if (!$username) { $username = $Credentials.GetNetworkCredential().UserName $password = $Credentials.GetNetworkCredential().Password } $message = "Creating variable groups in Azure DevOps" Write-Host $message try { $varGroupCICD = az pipelines variable-group create --organization https://dev.azure.com/$adoOrg --project $adoProject --name "$adoRepo.D365CDEnvironment" --variables d365username=$username --authorize $true | ConvertFrom-Json az pipelines variable-group variable create --organization https://dev.azure.com/$adoOrg --project $adoProject --name d365password --value $password --secret $true --group-id $varGroupCICD.id az pipelines variable-group variable create --organization https://dev.azure.com/$adoOrg --project $adoProject --name d365url --value $CICDEnvironment.WebApplicationUrl --group-id $varGroupCICD.id $message = "Creating Build and Deploy Pipeline in Azure DevOps" Write-Host $message $global:devops_projectFile.CICDEnvironmentName = $CICDEnvironment.FriendlyName $global:devops_projectFile.CICDEnvironmentURL = $CICDEnvironment.WebApplicationUrl $global:devops_projectFile.CICDVarGroupID = $varGroupCICD.id $global:devops_projectFile | ConvertTo-Json | Set-Content ("$global:devops_projectLocation\$global:devops_gitRepo.json") $pipeline = az pipelines create --organization https://dev.azure.com/$adoOrg --project $adoProject --name "$adoRepo.CI" --yml-path /build.yaml --repository $adoRepo --repository-type tfsgit --branch master | ConvertFrom-Json $global:devops_projectFile.CIPipeLineId = $pipeline.definition.id $global:devops_projectFile | ConvertTo-Json | Set-Content ("$global:devops_projectLocation\$global:devops_gitRepo.json") az pipelines show --organization https://dev.azure.com/$adoOrg --project $adoProject --id $pipeline.definition.id --open } catch { $global:devops_projectFile.CICDEnvironmentName = "Error" $global:devops_projectFile | ConvertTo-Json | Set-Content ("$global:devops_projectLocation\$global:devops_gitRepo.json") pause } } |