Skip to content

Commit

Permalink
fix: missing environment variables fails deployment (#84)
Browse files Browse the repository at this point in the history
* Deployment fails

Deployment fails when an environment variable is not found #80

* test: update unit test
* test: refactor powershell deployment to pac cli

Co-authored-by: DebaMaji <61949539+DebaMaji@users.noreply.github.com>
Co-authored-by: Tom Ashworth <tom.ashworth@capgemini.com>
Co-authored-by: Max Ewing <max.ewing@capgemini.com>
  • Loading branch information
3 people authored Jul 5, 2022
1 parent e89ac6e commit 92f498a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void SetEnvironmentVariable(string key, string value)
var definition = this.GetDefinitionByKey(key, new ColumnSet(false));
if (definition == null)
{
this.logger.LogError($"Environment variable {key} not found on target instance.");
this.logger.LogInformation($"Environment variable {key} not found on target instance.");
return;
}

Expand Down Expand Up @@ -121,4 +121,4 @@ private Entity GetDefinitionByKey(string key, ColumnSet columnSet)
columnSet).Entities.FirstOrDefault();
}
}
}
}
6 changes: 3 additions & 3 deletions templates/build-and-test-stages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ stages:
CurrencyName: GBP
DomainName: $(TestEnvironment.DomainName)
- powershell: |
echo "##vso[task.setvariable variable=EnvironmentUrl;isOutput=true]$env:BUILDTOOLS_ENVIRONMENTURL"
echo "##vso[task.setvariable variable=EnvironmentName;isOutput=true]$env:BUILDTOOLS_ENVIRONMENTID"
echo "##vso[task.setvariable variable=EnvironmentUrl;isOutput=true]$env:POWERPLATFORMCREATEENVIRONMENT_BUILDTOOLS_ENVIRONMENTURL"
echo "##vso[task.setvariable variable=EnvironmentName;isOutput=true]$env:POWERPLATFORMCREATEENVIRONMENT_BUILDTOOLS_ENVIRONMENTID"
displayName: Set output variables
name: SetEnvironmentOutputVariables
- stage: BuildAndTest
Expand Down Expand Up @@ -102,4 +102,4 @@ stages:
continueOnError: true
inputs:
authenticationType: PowerPlatformSPN
PowerPlatformSPN: Dataverse (placeholder)
PowerPlatformSPN: Dataverse (placeholder)
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public PackageDeployerFixture(IMessageSink diagnosticMessageSink)

if (process.ExitCode != 0)
{
throw new Exception("Script `DeployPackage.ps1` failed");
this.LogDiagnosticMessage("Script `DeployPackage.ps1` failed. Exit code: " + process.ExitCode);
}

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
$ErrorActionPreference = "Stop"
Write-Host "Installing PAC CLI..."

Install-Module -Name Microsoft.Xrm.Tooling.PackageDeployment.Powershell -Force -Scope CurrentUser
nuget install Microsoft.PowerApps.CLI -OutputDirectory pac

$pacNugetFolder = Get-ChildItem "pac" | Where-Object {$_.Name -match "Microsoft.PowerApps.CLI."}
$pacPath = $pacNugetFolder.FullName + "\tools"
$env:PATH = $env:PATH + ";" + $pacPath

$connectionString = "Url=$env:CAPGEMINI_PACKAGE_DEPLOYER_TESTS_URL; Username=$env:CAPGEMINI_PACKAGE_DEPLOYER_TESTS_USERNAME; Password=$env:CAPGEMINI_PACKAGE_DEPLOYER_TESTS_PASSWORD; AuthType=OAuth; AppId=51f81489-12ee-4a9e-aaae-a2591f45987d; RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97"
$packageName = "Capgemini.PowerApps.PackageDeployerTemplate.MockPackage.dll"
$packageDirectory = Get-Location
$pacAuthName = "$(New-Guid)".Replace("-", "").SubString(0, 20)

Write-Host "Create Auth profile with name $pacAuthName..."
pac auth create --name $pacAuthName --url $env:CAPGEMINI_PACKAGE_DEPLOYER_TESTS_URL --username $env:CAPGEMINI_PACKAGE_DEPLOYER_TESTS_USERNAME --password $env:CAPGEMINI_PACKAGE_DEPLOYER_TESTS_PASSWORD

try {
Write-Host "Running Deploy command..."
pac package deploy --package $packageName --logConsole
}
catch {
Write-Host "An error occurred:"
Write-Host $_.ScriptStackTrace
}
finally {
Write-Host "Deleting Auth profile with name $pacAuthName..."
pac auth delete --name $pacAuthName
}


Get-CrmPackages -PackageDirectory $packageDirectory -PackageName $packageName
Import-CrmPackage -CrmConnection $connectionString -PackageDirectory $packageDirectory -PackageName $packageName -LogWriteDirectory $packageDirectory -Verbose
exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void SetEnvironmentVariables_DefinitionDoesNotExist_LogNoVariableExist()
.Verifiable();

this.environmentVariableDeploymentService.SetEnvironmentVariables(environmentVariableConfigs);
this.loggerMock.VerifyLog(x => x.LogError($"Environment variable {environmentVariableConfigs.ElementAt(0).Key} not found on target instance."));
this.loggerMock.VerifyLog(x => x.LogInformation($"Environment variable {environmentVariableConfigs.ElementAt(0).Key} not found on target instance."));
}

[Fact]
Expand Down

0 comments on commit 92f498a

Please sign in to comment.