diff --git a/src/Capgemini.PowerApps.PackageDeployerTemplate/Services/EnvironmentVariableDeploymentService.cs b/src/Capgemini.PowerApps.PackageDeployerTemplate/Services/EnvironmentVariableDeploymentService.cs index 273cb8f..9a7a5c0 100644 --- a/src/Capgemini.PowerApps.PackageDeployerTemplate/Services/EnvironmentVariableDeploymentService.cs +++ b/src/Capgemini.PowerApps.PackageDeployerTemplate/Services/EnvironmentVariableDeploymentService.cs @@ -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; } @@ -121,4 +121,4 @@ private Entity GetDefinitionByKey(string key, ColumnSet columnSet) columnSet).Entities.FirstOrDefault(); } } -} \ No newline at end of file +} diff --git a/templates/build-and-test-stages.yml b/templates/build-and-test-stages.yml index d6f1e7d..3cc84b2 100644 --- a/templates/build-and-test-stages.yml +++ b/templates/build-and-test-stages.yml @@ -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 @@ -102,4 +102,4 @@ stages: continueOnError: true inputs: authenticationType: PowerPlatformSPN - PowerPlatformSPN: Dataverse (placeholder) \ No newline at end of file + PowerPlatformSPN: Dataverse (placeholder) diff --git a/tests/Capgemini.PowerApps.PackageDeployerTemplate.IntegrationTests/PackageDeployerFixture.cs b/tests/Capgemini.PowerApps.PackageDeployerTemplate.IntegrationTests/PackageDeployerFixture.cs index 25ff151..adc972b 100644 --- a/tests/Capgemini.PowerApps.PackageDeployerTemplate.IntegrationTests/PackageDeployerFixture.cs +++ b/tests/Capgemini.PowerApps.PackageDeployerTemplate.IntegrationTests/PackageDeployerFixture.cs @@ -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; diff --git a/tests/Capgemini.PowerApps.PackageDeployerTemplate.IntegrationTests/Resources/DeployPackage.ps1 b/tests/Capgemini.PowerApps.PackageDeployerTemplate.IntegrationTests/Resources/DeployPackage.ps1 index 7a28e0c..5caffc8 100644 --- a/tests/Capgemini.PowerApps.PackageDeployerTemplate.IntegrationTests/Resources/DeployPackage.ps1 +++ b/tests/Capgemini.PowerApps.PackageDeployerTemplate.IntegrationTests/Resources/DeployPackage.ps1 @@ -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 \ No newline at end of file +exit 0 \ No newline at end of file diff --git a/tests/Capgemini.PowerApps.PackageDeployerTemplate.UnitTests/Services/EnvironmentVariableDeploymentServiceTests.cs b/tests/Capgemini.PowerApps.PackageDeployerTemplate.UnitTests/Services/EnvironmentVariableDeploymentServiceTests.cs index bc91a68..5e7bd05 100644 --- a/tests/Capgemini.PowerApps.PackageDeployerTemplate.UnitTests/Services/EnvironmentVariableDeploymentServiceTests.cs +++ b/tests/Capgemini.PowerApps.PackageDeployerTemplate.UnitTests/Services/EnvironmentVariableDeploymentServiceTests.cs @@ -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]