|
| 1 | +--- |
| 2 | +title: 'Build a package' |
| 3 | +description: How to build your package |
| 4 | +search.appverid: MET150 |
| 5 | +author: Tinacyt |
| 6 | +ms.author: tinachen |
| 7 | +manager: rshastri |
| 8 | +audience: Software-Vendor |
| 9 | +ms.topic: troubleshooting |
| 10 | +ms.date: 02/28/2022 |
| 11 | +ms.service: virtual-desktop |
| 12 | +ms.localizationpriority: medium |
| 13 | +ms.collection: TestBase-M365 |
| 14 | +ms.custom: # This is an optional, free-form field you can use to define your own collection of articles. If you have more than one value, format as a bulleted list. This field truncates to something like 144 characters (inclusive of spaces) so keep it short. |
| 15 | +ms.reviewer: Tinacyt |
| 16 | +f1.keywords: NOCSH |
| 17 | +--- |
| 18 | + |
| 19 | +# Build a package |
| 20 | +A package is a .zip file containing your application binary and test scripts, which is the prerequisite to use Test Base. This QuickStart will guide you to build your first package, with which you can perform Out-of-box testing on your application. |
| 21 | + |
| 22 | +* *An **Out-of-Box (OOB)** test performs an install, launch, close, and uninstall of your application. After the install, the launch-close routine is repeated 30 times before a single uninstall is run. The OOB test provides you with standardized telemetry on your package to compare across Windows builds.* |
| 23 | + |
| 24 | +Optionally, you can download our [sample package](https://aka.ms/testbase-sample-package) to reference and begin with. |
| 25 | + |
| 26 | +## Create a folder structure |
| 27 | + |
| 28 | +In your local computer, create a folder structure as follows:<br> |
| 29 | + |
| 30 | + |
| 31 | +These folders are used: |
| 32 | +* **App\bin**: save the application and dependency binaries.<br> |
| 33 | +* **App\scripts**: save scripts to install, launch, close and uninstall your application.<br> |
| 34 | +* **App\logs**: scripts should output logs to this folder, then you can download and analyze logs after test is finished.<br> |
| 35 | + |
| 36 | +## Copy binary file(s) |
| 37 | +Copy your application installation files to **App\bin**. If your application has dependencies, they need to be installed first. Also, copy the dependency installation files to **App\bin**.<br> |
| 38 | + |
| 39 | + |
| 40 | +## Add PowerShell scripts |
| 41 | +To perform OOB test, you will need to add PowerShell scripts to install, launch, close, and uninstall your application. |
| 42 | +> [!NOTE] |
| 43 | +> *In OOB test, install, launch, and close scripts are required, while uninstall script is optional*. |
| 44 | + |
| 45 | +The script should be added to the folder as follows: |
| 46 | + |
| 47 | + |
| 48 | +A script usually includes the following behaviors:<br> |
| 49 | +- **Run the commands to install/launch/close/uninstall the application**. E.g., if your application is an MSI file, run [msiexec](/windows-server/administration/windows-commands/msiexec) to install it. <br> |
| 50 | +- **Check the result of install/launch/close/uninstall operation**, return zero exit code if the result is expected. Test Base will mark a script run as failure if it returns a non-zero exit code.<br> |
| 51 | +- **Save enough logs**, save proper logs for future use.<br> |
| 52 | + |
| 53 | +Please refer to the following examples. You can simply copy them to your files and make changes accordingly. <br> |
| 54 | + |
| 55 | +**Example of install script (App\scripts\install\job.ps1)** |
| 56 | +```powershell |
| 57 | + push-location $PSScriptRoot |
| 58 | + $exit_code = 0 |
| 59 | + $script_name = $myinvocation.mycommand.name |
| 60 | + $log_dir = "$PSScriptRoot\..\..\logs" |
| 61 | + $log_file = "$log_dir\$script_name.log" |
| 62 | +
|
| 63 | +
|
| 64 | + if(-not (test-path -path $log_dir )) { |
| 65 | + new-item -itemtype directory -path $log_dir |
| 66 | + } |
| 67 | +
|
| 68 | + Function log { |
| 69 | + Param ([string]$log_string) |
| 70 | + write-host $log_string |
| 71 | + add-content $log_file -value $log_string |
| 72 | + } |
| 73 | +
|
| 74 | + log("Installing TestBaseM365 Digital Clock") |
| 75 | + push-location "..\..\bin" |
| 76 | + if ([Environment]::Is64BitProcess) { |
| 77 | + $installer_name = "TestBaseM365DigitalClock.msi" |
| 78 | + } |
| 79 | + else { |
| 80 | + $installer_name = "TestBaseM365DigitalClock.msi" |
| 81 | + } |
| 82 | + $arguments = "/i "+$installer_name+" /quiet /L*v "+"$log_dir"+"\atp-client-installation.log" |
| 83 | +
|
| 84 | + $installer = Start-Process msiexec.exe $arguments -wait -passthru |
| 85 | + pop-location |
| 86 | +
|
| 87 | + if ($installer.exitcode -eq 0) { |
| 88 | + log("Installation succesful as $($installer.exitcode)") |
| 89 | + } |
| 90 | + else { |
| 91 | + log("Error: Installation failed as $($installer.exitcode)") |
| 92 | + $exit_code = $installer.exitcode |
| 93 | + } |
| 94 | +
|
| 95 | + log("Installation script finished as $exit_code") |
| 96 | + pop-location |
| 97 | + exit $exit_code |
| 98 | +``` |
| 99 | + |
| 100 | +**Example of launch script (App\scripts\launch\job.ps1)** |
| 101 | +```powershell |
| 102 | + push-location $PSScriptRoot |
| 103 | + $exit_code = 0 |
| 104 | + $script_name = $myinvocation.mycommand.name |
| 105 | + $log_dir = "$PSScriptRoot\..\..\logs" |
| 106 | + $log_file = "$log_dir\$script_name.log" |
| 107 | +
|
| 108 | + if(-not (test-path -path $log_dir )) { |
| 109 | + new-item -itemtype directory -path $log_dir |
| 110 | + } |
| 111 | +
|
| 112 | + Function log { |
| 113 | + Param ([string]$log_string) |
| 114 | + write-host $log_string |
| 115 | + add-content $log_file -value $log_string |
| 116 | + } |
| 117 | +
|
| 118 | + log("Launch TestBaseM365 Digital Clock") |
| 119 | +
|
| 120 | + $PROCESS_NAME = "DigitalClock" |
| 121 | + $exePath = "C:\Program Files\Test Base M365\DigitalClock\DigitalClock.exe" |
| 122 | +
|
| 123 | + Start-Process -FilePath $exePath |
| 124 | +
|
| 125 | + if (Get-Process -Name $PROCESS_NAME) { |
| 126 | + log("Launch successfully $PROCESS_NAME...") |
| 127 | + $exit_code = 0 |
| 128 | + } |
| 129 | + else { |
| 130 | + log("Not launched $PROCESS_NAME...") |
| 131 | + $exit_code = 1 |
| 132 | + } |
| 133 | +
|
| 134 | + log("Launch script finished as $exit_code") |
| 135 | + pop-location |
| 136 | + exit $exit_code |
| 137 | +``` |
| 138 | + |
| 139 | +## Compress to zip file |
| 140 | +After scripts and binaries are prepared, you proceed to compress the folder to a zip file. Right click on the App folder, select **Compress to ZIP file**.<br> |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | +## Verify your package locally (optional) |
| 145 | +After building the zip package, you can upload it to your Test Base account. <br> |
| 146 | +However, it's best practice to run the test locally to ensure the scripts work properly before uploading. A local test can quickly identify issues and speed up your uploading process. To verify locally follow the steps below:<br> |
| 147 | +1. Prepare a VM (Virtual Machine)<br> |
| 148 | + We recommend using a virtual machine for this local test since a clean Windows environment is currently needed for each test. It's easy to create a Windows VM on Azure ([Quickstart: Windows virtual machine](/azure/virtual-machines/windows/quick-create-portal)), you can select a proper Windows version (image) for your test, e.g., *Windows 10 Pro, version 21H2.*<br> |
| 149 | + |
| 150 | +2. Copy your package to the VM<br> |
| 151 | + There are many ways to copy your package file to the VM. If you're using an Azure VM, you can choose to: |
| 152 | + - Copy file directly in your Remote Desktop connection. <br> |
| 153 | + - Use Azure file share ([Quickstart: Create and manage Azure file](/azure/storage/files/storage-files-quick-create-use-windows)) |
| 154 | + |
| 155 | + You can create a specific folder for this test and copy the package file under this folder. e.g., *C:\TestBase*.<br> |
| 156 | +3. Test the package<br> |
| 157 | + Open Windows PowerShell, switch to the directory containing the package, e.g., cd C:\TestBase, and start to run your tests on the package:<br> |
| 158 | + a. Extract the package file. |
| 159 | + - *Expand-Archive -LiteralPath C:\TestBase\App.zip -DestinationPath C:\TestBase*<br> |
| 160 | + |
| 161 | + b. Run install script. |
| 162 | + - *C:\TestBase\App\scripts\install\job.ps1*<br> |
| 163 | + |
| 164 | + c. Restart the VM if necessary.<br> |
| 165 | + |
| 166 | + d. Run launch script. |
| 167 | + - *C:\TestBase\App\scripts\install\job.ps1*<br> |
| 168 | + |
| 169 | + e. Run close script. |
| 170 | + - *C:\TestBase\App\scripts\close\job.ps1*<br> |
| 171 | + |
| 172 | + f. Run uninstall script (if you have one). |
| 173 | + - *C:\TestBase\App\scripts\uninstall\job.ps1*<br> |
| 174 | + |
| 175 | + After each step, you can check if there are any issues in your script. If all scripts run as expected, your package is ready to be uploaded to your Test Base account. |
| 176 | + |
| 177 | + |
| 178 | +## Next steps |
| 179 | +[Upload a package](uploadApplication.md) |
| 180 | + |
| 181 | + |
0 commit comments