microsoft / navcontainerhelper

Official Microsoft repository for BcContainerHelper, a PowerShell module, which makes it easier to work with Business Central Containers on Docker.
MIT License
384 stars 247 forks source link

Problems with Run-AlPipeline and NewBCContainer #2391

Closed nancy-ottenklinger closed 2 years ago

nancy-ottenklinger commented 2 years ago

Describe the issue I use Run-AlPipeline with a NewBCContainer Overwrite. I get the following error with my script:

Get-Item : Cannot find path 'D:\a\HelloWorldTest\HelloWorldTest\Invoke-Command\ServiceTier\program files\Microsoft 
Dynamics NAV' because it does not exist.
At C:\Users\runneradmin\AppData\Local\Temp\ed9d9ff2-158d-46d1-a7de-cf58b7123514\ContainerHandling\New-NavContainer.ps1:
930 char:28
+ ... vversion = (Get-Item -Path "$dvdPath\ServiceTier\program files\Micros ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (D:\a\HelloWorld...ft Dynamics NAV:String) [Get-Item], ItemNotFoundExcep 
   tion
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand

I looked at the New-NavContainer.ps1 Z. 930 to see if I forgot to set an parameter. But I don't understand why the else-part in the query was choosen as I have set an artifactUrl. Is something else missing in the parameters for NewBCContainer?

Scripts used to create container and cause the issue

$Parameters = @{        
        "accept_eula" = $true
        "containerName" = $containerName
        "imageName" = $imageName
        "artifactUrl" = $artifact
        "auth" = "UserPassword"  
    "Credential" = $cred
        "updateHosts" = $true
        "licenseFile" = $licenseFile
        "MemoryLimit" = $memoryLimit
    "bakfile" = $bakfile
    "includeTestToolkit" = $true
    "includeAL" = $true
         }

Run-AlPipeline @params `
    -pipelinename $pipelineName `
    -containerName $containerName `
    -imageName $imageName `
    -bcAuthContext $authContext `
    -environment $environmentName `
    -artifact $artifact.replace('{INSIDERSASTOKEN}',$insiderSasToken) `
    -memoryLimit $memoryLimit `
    -baseFolder $baseFolder `
    -licenseFile $LicenseFile `
    -installApps $installApps `
    -installTestApps $installTestApps `
    -appFolders $appFolders `
    -testFolders $testFolders `
    -doNotRunTests:$doNotRunTests `
    -testResultsFile $testResultsFile `
    -testResultsFormat 'JUnit' `
    -installTestRunner:$installTestRunner `
    -installTestFramework:$installTestFramework `
    -installTestLibraries:$installTestLibraries `
    -installPerformanceToolkit:$installPerformanceToolkit `
    -enableCodeCop:$enableCodeCop `
    -enableAppSourceCop:$enableAppSourceCop `
    -enablePerTenantExtensionCop:$enablePerTenantExtensionCop `
    -enableUICop:$enableUICop `
    -azureDevOps:($environment -eq 'AzureDevOps') `
    -gitLab:($environment -eq 'GitLab') `
    -gitHubActions:($environment -eq 'GitHubActions') `
    -failOn 'error' `
    -AppSourceCopMandatoryAffixes $appSourceCopMandatoryAffixes `
    -AppSourceCopSupportedCountries $appSourceCopSupportedCountries `
    -additionalCountries $additionalCountries `
    -buildArtifactFolder $buildArtifactFolder `
    -CreateRuntimePackages:$CreateRuntimePackages `
    -appBuild $appBuild -appRevision $appRevision  `
    -NewBcContainer { param([hashtable]$Parameters)
        $Parameters.artifactUrl = $artifact
        New-BcContainer @Parameters Invoke-Command -scriptblock { $progressPreference = 'SilentlyContinue' } }

Full output of scripts


Run scripts\DevOps-Pipeline.ps1
Version not defined, using ci
Set artifact = //18.2.26217.26490/de
Set pipelineName = HelloWorld-ci
Set containerName = helloworld-ci
Set installApps = ''
Set installTestApps = ''
Set previousApps = 'https://businesscentralapps.blob.core.windows.net/githubhelloworld/latest/apps.zip'
Set appSourceCopMandatoryAffixes = ''
Set appSourceCopSupportedCountries = ''
Set appFolders = 'app,base'
Set testFolders = 'test'
Set memoryLimit = '6G'
Set additionalCountries = ''
Set genericImageName = ''
Set vaultNameForLocal = 'BuildVariables'
Set bcContainerHelperVersion = 'dev'
Set installTestRunner = True
Set installTestFramework = False
Set installTestLibraries = False
Set installPerformanceToolkit = False
Set enableCodeCop = False
Set enableAppSourceCop = False
Set enablePerTenantExtensionCop = True
Set enableUICop = True
Set doNotSignApps = True
Set doNotRunTests = False
Set cacheImage = True
Set CreateRuntimePackages = True
Downloading https://github.com/microsoft/navcontainerhelper/archive/dev.zip
BcContainerHelper version 3.0.5-dev
BcContainerHelper emits usage statistics telemetry to Microsoft
refreshToken:  
environmentName:  
Parameters
    _____                               _                
   |  __ \                             | |               
   | |__) |_ _ _ __ __ _ _ __ ___   ___| |_ ___ _ __ ___ 
   |  ___/ _` | '__/ _` | '_ ` _ \ / _ \ __/ _ \ '__/ __|
   | |  | (_| | | | (_| | | | | | |  __/ |_  __/ |  \__ \
   |_|   \__,_|_|  \__,_|_| |_| |_|\___|\__\___|_|  |___/

  Pipeline name               HelloWorld-ci
  Container name              helloworld-ci
  Image name                  bcimage
  ArtifactUrl                 https://bcartifacts.azureedge.net/sandbox/18.2.26217.26754/de
  SasToken                    Not Specified
  BcAuthContext               Not Specified
  Environment                 
  ReUseContainer              False
  KeepContainer               False
  Auth                        UserPassword
  Credential                  admin/Meta6173
  CompanyName                 
  MemoryLimit                 6G
  Enable Task Scheduler       False
  Assign Premium Plan         False
  Install Test Runner         True
  Install Test Framework      False
  Install Test Libraries      False
  Install Perf. Toolkit       False
  InstallOnlyReferencedApps   False
  CopySymbolsFromContainer    False
  enableCodeCop               False
  enableAppSourceCop          False
  enableUICop                 True
  enablePerTenantExtensionCop True
  doNotPerformUpgrade         False
  uninstallRemovedApps        False
  escapeFromCops              False
  doNotBuildTests             False
  doNotRunTests               False
  doNotRunBcptTests           False
  useDefaultAppSourceRuleSet  False
  rulesetFile                 
  azureDevOps                 False
  gitLab                      False
  gitHubActions               True
  License file                Not specified
  CodeSignCertPfxFile         Not specified
  CodeSignCertPfxPassword     Not specified
  CodeSignCertIsSelfSigned    False
  KeyVaultCertPfxFile         Not specified
  KeyVaultCertPfxPassword     Not specified
  KeyVaultClientId            
  TestResultsFile             D:\a\HelloWorldTest\HelloWorldTest\TestResults.xml
  BcptTestResultsFile         D:\a\HelloWorldTest\HelloWorldTest\bcptTestResults.json
  TestResultsFormat           JUnit
  AdditionalCountries         
  PackagesFolder              D:\a\HelloWorldTest\HelloWorldTest\.packages
  OutputFolder                D:\a\HelloWorldTest\HelloWorldTest\.output
  BuildArtifactFolder         D:\a\HelloWorldTest\HelloWorldTest\output
  CreateRuntimePackages       True
  AppVersion                  
  AppBuild                    0
  AppRevision                 0
  Install Apps
  - None
  Install Test Apps
  - None
  Previous Apps
  - None
  Application folders
  - D:\a\HelloWorldTest\HelloWorldTest\app
  - D:\a\HelloWorldTest\HelloWorldTest\base
  Test application folders
  - D:\a\HelloWorldTest\HelloWorldTest\test
  BCPT Test application folders
  - None
  Custom CodeCops
  - None
  NewBccontainer override
   param([hashtable]$Parameters)
        $Parameters.artifactUrl = $artifact
          New-BcContainer @Parameters Invoke-Command -scriptblock { $progressPreference = 'SilentlyContinue' } 
Pulling Generic Image

    _____       _ _ _                                          _        _                            
   |  __ \     | | (_)                                        (_)      (_)                           
   | |__) |   _| | |_ _ __   __ _    __ _  ___ _ __   ___ _ __ _  ___   _ _ __ ___   __ _  __ _  ___ 
   |  ___/ | | | | | | '_ \ / _` |  / _` |/ _ \ '_ \ / _ \ '__| |/ __| | | '_ ` _ \ / _` |/ _` |/ _ \
   | |   | |_| | | | | | | | (_| | | (_| |  __/ | | |  __/ |  | | (__  | | | | | | | (_| | (_| |  __/
   |_|    \__,_|_|_|_|_| |_|\__, |  \__, |\___|_| |_|\___|_|  |_|\___| |_|_| |_| |_|\__,_|\__, |\___|
                             __/ |   __/ |                                                 __/ |     
                            |___/   |___/                                                 |___/      

  Pulling mcr.microsoft.com/businesscentral:10.0.17763.2686

  Pulling generic image took 297 seconds
Creating Container

     _____                _   _                               _        _                 
    / ____|              | | (_)                             | |      (_)                
   | |     _ __ ___  __ _| |_ _ _ __   __ _    ___ ___  _ __ | |_ __ _ _ _ __   ___ _ __ 
   | |    | '__/ _ \/ _` | __| | '_ \ / _` |  / __/ _ \| '_ \| __/ _` | | '_ \ / _ \ '__|
   | |____| | |  __/ (_| | |_| | | | | (_| | | (__ (_) | | | | |_ (_| | | | | |  __/ |   
    \_____|_|  \___|\__,_|\__|_|_| |_|\__, |  \___\___/|_| |_|\__\__,_|_|_| |_|\___|_|   
                                       __/ |                                             
                                      |___/                                              

  BcContainerHelper is version 3.0.5-dev
  BcContainerHelper is running as administrator
  Host is Microsoft Windows Server 2019 Datacenter - ltsc2019
  Docker Client Version is 20.10.7
  Docker Server Version is 20.10.7
  Downloading application artifact /sandbox/18.2.26217.26754/de
  Downloading C:\Users\runneradmin\AppData\Local\Temp\7463cd24-188a-4a60-9a2c-6b1f2891fe0e.zip
  Unpacking application artifact to tmp folder using 7zip
  Downloading platform artifact /sandbox/18.2.26217.26754/platform
  Downloading C:\Users\runneradmin\AppData\Local\Temp\e32eb1b4-4c9b-4b1a-b154-46a8edb311e3.zip
  Unpacking platform artifact to tmp folder using 7zip
  Downloading Prerequisite Components
  Downloading c:\bcartifacts.cache\sandbox\18.2.26217.26754\platform\Prerequisite Components\Open XML SDK 2.5 for Microsoft Office\OpenXMLSDKv25.msi
  Downloading c:\bcartifacts.cache\sandbox\18.2.26217.26754\platform\Prerequisite Components\IIS URL Rewrite Module\rewrite_2.0_rtw_x64.msi
  Downloading c:\bcartifacts.cache\sandbox\18.2.26217.26754\platform\Prerequisite Components\DotNetCore\DotNetCore.1.0.4_1.1.1-WindowsHosting.exe
  Fetching all docker images
  Fetching all docker volumes
  ArtifactUrl and ImageName specified
  Building multitenant image bcimage:sandbox-18.2.26217.26754-de-mt based on mcr.microsoft.com/businesscentral:10.0.17763.2686 with https://bcartifacts.azureedge.net/sandbox/18.2.26217.26754/de
  Pulling latest image mcr.microsoft.com/businesscentral:10.0.17763.2686
  10.0.17763.2686: Pulling from businesscentral
  Digest: sha256:6116cdec65e9a3f6d41ba47319d296c1c6b42395327ffdffc9b65b0005823176
  Status: Image is up to date for mcr.microsoft.com/businesscentral:10.0.17763.2686
  mcr.microsoft.com/businesscentral:10.0.17763.2686
  Generic Tag: 1.0.2.1
  Container OS Version: 10.0.17763.2686 (ltsc2019)
  Host OS Version: 10.0.17763.2686 (ltsc2019)
  Using process isolation
  Files in c:\bcartifacts.cache\n3zywirq.r0s\my:
  Copying Platform Artifacts
  c:\bcartifacts.cache\sandbox\18.2.26217.26754\platform
  Copying Database
  Copying Licensefile
  Copying ConfigurationPackages
  C:\bcartifacts.cache\sandbox\18.2.26217.26754\de\ConfigurationPackages
  Copying Extensions
  C:\bcartifacts.cache\sandbox\18.2.26217.26754\de\Extensions
  Copying Applications.DE
  C:\bcartifacts.cache\sandbox\18.2.26217.26754\de\Applications.DE
  c:\bcartifacts.cache\n3zywirq.r0s
  Sending build context to Docker daemon  2.011GB

  Step 1/6 : FROM mcr.microsoft.com/businesscentral:10.0.17763.2686
   ---> 6f30fec3aafa
  Step 2/6 : ENV DatabaseServer=localhost DatabaseInstance=SQLEXPRESS DatabaseName=CRONUS IsBcSandbox=Y artifactUrl=https://bcartifacts.azureedge.net/sandbox/18.2.26217.26754/de filesOnly=False
   ---> Running in cdc641e7029c
  Removing intermediate container cdc641e7029c
   ---> 803c965046d8
  Step 3/6 : COPY my /run/
   ---> 44af65ac7a6f
  Step 4/6 : COPY NAVDVD /NAVDVD/
   ---> e4e86c5f004f
  Step 5/6 : RUN \Run\start.ps1 -installOnly -multitenant
   ---> Running in 1f236a2355e6
  Using installer from C:\Run\150-new
  Installing Business Central
  Installing from DVD
  Starting Local SQL Server
  WARNING: Waiting for service 'SQL Server (SQLEXPRESS) (MSSQL$SQLEXPRESS)' to 
  start...
  Starting Internet Information Server
  Copying Service Tier Files
  C:\NAVDVD\ServiceTier\Program Files
  C:\NAVDVD\ServiceTier\System64Folder
  Copying PowerShell Scripts
  C:\NAVDVD\WindowsPowerShellScripts\Cloud\NAVAdministration
  C:\NAVDVD\WindowsPowerShellScripts\WebSearch
  Copying dependencies
  Copying ReportBuilder
  Importing PowerShell Modules
  Determining Database Collation
  Restoring CRONUS Demo Database
  Setting CompatibilityLevel for tenant on localhost\SQLEXPRESS
  Exporting Application to CRONUS
  Removing Application from tenant
  Modifying Business Central Service Tier Config File for Docker
  Creating Business Central Service Tier
  Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
  Copying Web Client Files
  C:\NAVDVD\WebClient\Microsoft Dynamics NAV
  Copying Client Files
  C:\NAVDVD\LegacyDlls\program files\Microsoft Dynamics NAV
  C:\NAVDVD\LegacyDlls\program files\Microsoft Dynamics NAV
  C:\NAVDVD\LegacyDlls\systemFolder
  Copying ModernDev Files
  C:\NAVDVD
  C:\NAVDVD\ModernDev\program files\Microsoft Dynamics NAV
  Copying additional files
  Copying ConfigurationPackages
  C:\NAVDVD\ConfigurationPackages
  Copying Test Assemblies
  C:\NAVDVD\Test Assemblies
  Copying Extensions
  C:\NAVDVD\Extensions
  Copying Applications
  C:\NAVDVD\Applications
  Copying Applications.DE
  C:\NAVDVD\Applications.DE
  Starting Business Central Service Tier
  Importing CRONUS license file
  Copying Database on localhost\SQLEXPRESS from tenant to default
  Taking database tenant offline
  Copying database files
  Attaching files as new Database default
  Putting database tenant back online
  Mounting tenant database
  Mounting Database for default on server localhost\SQLEXPRESS with AllowAppDatabaseWrite = False
  Sync'ing Tenant
  Tenant is Operational
  Stopping Business Central Service Tier
  Installation took 222 seconds
  Installation complete
  Removing intermediate container 1f236a2355e6
   ---> 52c519464dc0
  Step 6/6 : LABEL legal="http://go.microsoft.com/fwlink/?LinkId=837447"       created="202204070658"       nav=""       cu=""       multitenant="Y" country="DE"       version="18.2.26217.26754"       platform="18.0.262[13](https://github.com/nancy-ottenklinger/HelloWorldTest/runs/5863734791?check_suite_focus=true#step:6:13).26669"
   ---> Running in 528f11de1f31
  Removing intermediate container 528f11de1f31
   ---> 50ba59ec4a67
  Successfully built 50ba59ec4a67
  Successfully tagged bcimage:sandbox-18.2.26217.26754-de-mt
  Building image took 615 seconds
  Using image bcimage:sandbox-18.2.26217.26754-de-mt
  New-BcContainer Telemetry Correlation Id: 956bdd86-f817-4a53-8675-9858a057c19d
Removing Container
  Removing C:\ProgramData\BcContainerHelper\Extensions\helloworld-ci
Run-AlPipeline Telemetry Correlation Id: 712cde04-45c1-4ca2-b570-d9593d32d96f
Get-Item : Cannot find path 'D:\a\HelloWorldTest\HelloWorldTest\Invoke-Command\ServiceTier\program files\Microsoft 
Dynamics NAV' because it does not exist.
At C:\Users\runneradmin\AppData\Local\Temp\ed9d9ff2-158d-46d1-a7de-cf58b71235[14](https://github.com/nancy-ottenklinger/HelloWorldTest/runs/5863734791?check_suite_focus=true#step:6:14)\ContainerHandling\New-NavContainer.ps1:
930 char:[28](https://github.com/nancy-ottenklinger/HelloWorldTest/runs/5863734791?check_suite_focus=true#step:6:28)
+ ... vversion = (Get-Item -Path "$dvdPath\ServiceTier\program files\Micros ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (D:\a\HelloWorld...ft Dynamics NAV:String) [Get-Item], ItemNotFoundExcep 
   tion
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand

Error: Process completed with exit code 1.

Thanks for your help.
freddydk commented 2 years ago

It looks like you are missing a ; between the new-BcContainer command and Invoke-ScriptInbcContainer command. PowerShell sees Invoke-ScriptInBcContainer as a parameter to New-BcContainer.

Furthermore: I don't understand why you are having $parameters defined before your Run-AlPipeline - these parameters are never used. The ScriptBlock gets the calculated parameters transferred as a parameter and your global variable will be ignored. Even if you rename the variable - this is not the way to do it. You should set parameters on the parameters transferred as a parameter ( [HashTable] $parameters ) - not just use your own.