Azure DevTest Labs: Artifacts
Artifacts allow you to install applications after you provision your Virtual Machine. In this article, I will discuss how you can use a storage account to install applications that may not be suitable to be published on the internet.
Create File Share
- From the Azure portal
- Find and select the resource group that is associated with your lab.
- Click on Files.
- Click on File Share.
- Provide the new file share with a Name and Quota. Click Ok.
- Select the file share you just created and click on Connect.
- Copy the powershell code into VScode and make note of the Username and Password.
Add secrets to KeyVault
- Go to your Lab and select My secrets
- Under name type: SAname and for value add the username of the file share (ex:azure\DTLinstalls5597) and hit enter.
- Under name type: SApassword and for the value add the password.
- Create another secret for the Storage Account UNC file share.
Create Artifacfile.json
User the following sample to create the Artifactfile.json to provide the username and password from the KeyVault.
{
"$schema": "https://raw.githubusercontent.com/Azure/azure-devtestlab/master/schemas/2016-11-28/dtlArtifacts.json",
"title": "Sample App",
"description": "Sample app for DTL demo ",
"tags": [
"Windows"
],
"iconUri": "",
"targetOsType": "Windows",
"parameters": {
"Username": {
"type": "securestring",
"displayName": "Username",
"description": "Azure storage file share user account"
},
"Password": {
"type": "securestring",
"displayName": "Password",
"description": "Azure storage file share user password"
},
"StorageAccount": {
"type": "securestring",
"displayName": "Storage Account Name",
"description": "Azure storage account name"
}
},
"runCommand": {
"commandToExecute": "[concat('powershell.exe -ExecutionPolicy bypass \"& ./installSampleApp.ps1', ' -Username ', parameters('Username'), ' -Password ''', parameters('Password'), ''' -storageaccount ', parameters('storageaccount')']"
}
}
Create PowerShell script to install application
User the following sample to create the installSampleApp.ps1
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string] $Username,
[Parameter(Mandatory = $true)]
[string] $Password,
[Parameter(Mandatory = $true)]
[string] $SAaccount
)
$sampleAPP = "Z:\sample.exe"
try
{
$acctKey = ConvertTo-SecureString -String "$password" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential -ArgumentList "$username", $acctKey
New-PSDrive -Name Z -PSProvider FileSystem -Root "$SAaccount" -Credential $credential
}
catch
{
Write-Error "Failed to map network drive to Azure Storage Account"
}
try
{
Start-Process -FilePath $sampleAPP -ArgumentList "/SILENT"
}
catch
{
Write-Error 'Failed to install application'
}
Once you have created the sample application, add it to your custom repository in DevTest Labs and test the installation of the artifact.