- Article
This article tells you how to get oneartefactrepository to your lab in Azure DevTest Labs. Artifacts are tools or applications that can be installed on virtual machines (VMs). You define artifacts in a JSON file that you load from a GitHub or Azure Repos Git repository.
PublicDevTest Labs GitHub-artefactopslagplaatsprovides many common artifacts for Windows and Linux. The artifacts in this public repository are available in DevTest Labs by default. For information on adding artifacts to VMs, seeAdd artifacts to DevTest Labs VMs.
You can also create custom artifacts that are not available in the public artifact repository. For more information on creating custom artifacts, seeCreate custom artifacts. You can add your custom artifacts to your own artifact repository and add the repository to your lab so that all lab users can use the artifacts.
This article shows you how to add an artifact repository to your lab using the Azure portal, an Azure Resource Management (ARM) template, or Azure PowerShell. You can also use an Azure PowerShell or Azure CLI script to automatically add an artifact repository to a lab.
Remark
We recommend using the Azure Az PowerShell module to interact with Azure. To seeInstalleer Azure PowerShellstart. For more information about migrating to the Az PowerShell module, seeMigrate Azure PowerShell from AzureRM to Az.
Requirements
To add an artifact repository to a lab, you need to know the Git HTTPS clone URL and personal access token for the GitHub or Azure repository that contains the artifact files.
Download the clone URL and personal access token for GitHub
- From the home page, select the GitHub repository containing your artifactsCode, and belowClone, copy the HTTPS URL.
- Select your profile picture in the top right corner of GitHub and then selectInstitutions.
- Select on your profile page in the left menuDeveloper settingsand then selectPersonal access tokens.
- SelectGenerate a new token.
- On theNew personal access tokenpage, belowRemark, enter an optional description for the token. Accept all defaults and then selectGenerate token.
- Save the generated token.
Download the clone URL and personal access token for Azure repositories
- From the main page of the repository containing your artifacts, selectClone. On theClone repositorypage, copy the clone URL.
- Select in the top right corner of the Azure DevOps pageUser settings>Personal access tokens.
- On thePersonal access tokenspage, selectNew sign.
- Fill in the information for the token and selectReadfor the ranges, and then selectTo create.
- On theSuccespage, make sure you copy the token because Azure Repos does not store or display the token again.
Add an artifact repository to a lab in the Azure portal
At the labOverviewpage, selectConfiguration and Policyfrom the left navigation.
On theConfiguration and Policypage, selectRepositoriesbelowExternal Resourcesin the left navigation.
On theRepositoriespage, thePublic Artifact Repois automatically present and connects to theDevTest Labs public GitHub repository. If this repository is not enabled for your lab, you can enable it by selecting the checkbox next to itPublic Artifact Repoand then selectSwitchin the top menu bar.
Select to add your artifact repository to the labAddin the top menu bar.
(Video) How To Create Custom Artifacts For Virtual Machines In An Azure DevTest LabIn theStorage placeenter the following information:
- Name: A repository name for use in the lab.
- Git clone URL: The Git HTTPS clone URL from GitHub or Azure Repos.
- So(optional): The branch that has your artifact definitions.
- Personal access token: The GitHub or Azure Repos personal access token.
- The map pad: The directory for your ARM template definitions, relative to the Git clone URL. Be sure to include the first forward slash in the folder path.
SelectRedden.
The repository will now appear in theRepositorieslab list.
Add an artifact repository using an ARM template
ARM templates are JSON files that describe Azure resources to be created. For more information about ARM templates, seeUnderstand the structure and syntax of ARM templates.
The following ARM template adds an artifact repository to a lab. The template creates the lab if it doesn't already exist.
View the ARM template
The sample template collects the following information in parameters. Some parameters have default values, but the deployment command must specify the lab name, artifact repository URI, repository type, and repository private access token.
- lab name.
- Display name for the artifact repository in DevTest Labs. The default value is
Team Repository
. - URI of the artifact repository, which you copied earlier.
- Repository branch that contains the artifacts. The default value is
main
. - Name of the folder containing the artifacts. The default value is:
/Artifacts
. - Repository type. The allowed values are
VsoGit
, for Azure Repos, orGitHub
. - Personal access token for the repository, which you copied earlier.
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "labName ": { "type": "string" }, "artifactRepositoryDisplayName": { "type": "string", "defaultValue": "Team Repository" }, "artifactRepoUri": { "type": "string" }, " artefactRepoBranch": { "type": "string", "defaultValue": "main" }, "artifactRepoFolder": { "type": "string", "defaultValue": "/Artifacts" }, "artifactRepoType": { " type": "string", "allowedValues": ["VsoGit", "GitHub"] }, "artifactRepoSecurityToken": { "type": "securestring" } }, "variables": { "artifactRepositoryName": "[concat( 'Repo-', uniqueString(subscription().subscriptionId))]" }, "resources": [{ "apiVersion": "2016-05-15", "type": "Microsoft.DevTestLab/labs", "name ": "[parameters('labName')]", "location": "[resourceGroup().location]", "resources": [ { "apiVersion": "2016-05-15", "name": " [variabelen('artifactRepositoryName')]", "type": "artifactSources", "dependsOn": [ "[resourceId('Microsoft.DevTestLab/labs', parameters('labName'))]" ], "properties": { "uri": "[parameters('artifactRepoUri')]", "folderPath": "[parameters('artifactRepoFolder')]", "branchRef": "[parameters('artifactRepoBranch')]", "displayName": "[parameters('artifactRepositoryDisplayName')]", "securityToken": "[parameters('artifactRepoSecurityToken')]", "sourceType": "[parameters('artifactRepoType')]", "status": "Ingeschakeld" } } ] } ]}
Implement the template
There are several ways to deploy ARM templates to create or update Azure resources. For information and instructions, see the following articles:
- Deploy resources with ARM templates and Azure PowerShell
- Deploy resources with ARM templates and Azure CLI
- Deploy resources with ARM templates in the Azure portal
- Deploy resources with ARM templates and Resource Manager REST API
For this example, deploy the template using Azure PowerShell.
Remark
The cmdlets that deploy the template are context-specific, so they use the current tenant and subscription. To change the context, useSet-AzContextbefore deploying the template
Create a resource group usingNew-AzResourceGroup. Skip this step if the resource group you want to use already exists.
(Video) Learn Azure DevTest Labs Step by Step #devopstutorial #azurecloud #devtestlabs #azuretrainingNew-AzResourceGroup -Name MyLabResourceGroup1 -Locatie westus
Create a deployment to the resource group usingNew-AzResourceGroupDeployment. You can create multiple resource deployments for the same resource group. If you deploy to the same resource group multiple times, make sure each deployment name is unique.
New-AzResourceGroupDeployment ` -Name MyLabResourceGroup-Deployment1 ` -ResourceGroupName MyLabResourceGroup1 ` -TemplateFile azuredeploy.json ` -TemplateParameterFile azuredeploy.parameters.json
AlreadyNew-AzResourceGroupDeployment
runs successfully, the output shows important information, such as the provisioning state, which it should bepassed
, and any output for the template.
Add an artifact repository using Azure PowerShell
The following sample PowerShell script,New-DevTestLabArtifactRepository.ps1, adds an artifact repository to a lab. The full script contains some extensive messages and comments.
<#.SYNOPSISThis script creates a new custom repository and adds it to an existing DevTest Lab..PARAMETER LabNameThe name of the lab..PARAMETER LabResourceGroupNameThe name of the resource group containing the lab..PARAMETER ArtifactRepositoryNameName for the new artifact repository. The script creates a random name for the repository if not specified..PARAMETER ArtifactRepositoryDisplayNameDisplay name for the artifact repository.This name appears in the list of artifact repositories for a lab..PARAMETER RepositoryUriUri to the artifact repository..PARAMETER RepositoryBranchBranch containing the artifact files . Defaults to 'main'..PARAMETER FolderPathFolder which contains the artifact files. Defaults to '/Artifacts'.PARAMETER PersonalAccessTokenPersonal access token for the GitHub or Azure Repos repository..PARAMETER SourceTypeWhether the artifact repository is a VSOGit (Azure Repos) or GitHub repository..EXAMPLESet-AzContext -SubscriptionId 11111111-1111-1111-1111 - 111111111111.\New-DevTestLabArtifactRepository.ps1 -LabName "mydevtestlab" -LabResourceGroupName "mydtlrg" -ArtifactRepositoryName "MyTeam Repository" -RepositoryUri "https://github.com//.git" -PersonalAccessToken "1111. ..." -SourceType "GitHub".NOTE The script uses the current Azure context. Use Set-AzContext.#>[CmdletBinding()]Param( [Parameter(Mandatory=$true)] $LabName, [Parameter(Mandatory= $true)] $LabResourceGroupName, $ArtifactRepositoryName, $ArtifactRepositoryDisplayName = 'to set context. Team Artifact Repository', [Parameter(Required=$true)] $RepositoryUri, $RepositoryBranch = 'main', $FolderPath = '/ Artifacts', [Parameter(Required=$true)] $PersonalAccessToken, [Parameter(Required=$true)] [ValidateSet('VsoGit', 'GitHub')] $SourceType)# Set the internal name of the artifact repository if not specified.if ($ArtifactRepositoryName -eq $null){ $ArtifactRepositoryName = "PrivateRepo" + (Get-Random - Up to 999)}# Log in to Azure.Connect-AzAccount#Get Lab Resource.$LabResource = Get-AzResource -ResourceType ' Microsoft.DevTestLab/labs' -ResourceName $LabName -ResourceGroupName $LabResourceGroupNameWrite-Verbose "Lab Name: $($LabResource.Name)"Write-Verbose "Lab Resource Group Name: $($LabResource.ResourceGroupName)"Write-Verbose "Lab Resource Location: $($LabResource.Location)"Write-Verbose "Artifact Repository Internal Name: $ArtifactRepositoryName" #Prepare properties object for the call to New-AzResource.$propertiesObject = @{ uri = $RepositoryUri; folderPath = $FolderPath; branchRef = $RepositoryBranch; displayName = $ArtifactRepositoryDisplayName; securityToken = $PersonalAccessToken; sourceType = $SourceType; status = 'Enabled'}Write-Verbose "Properties to pass to New-AzResource:$($propertiesObject | Out-String)"#Add resource to current subscription.$resourcetype = 'Microsoft.DevTestLab/labs/artifactSources '$resourceName = $LabName + '/' + $ArtifactRepositoryNameWrite-Verbose "Az ResourceType: $resourcetype"Write-Verbose "Az ResourceName: $resourceName"Write-Verbose "Create Artifact Repository '$ArtifactRepositoryDisplayName'..."$result = New- AzResource -Location $LabResource.Location -ResourceGroupName $LabResource.ResourceGroupName -properties $propertiesObject -ResourceType $resourcetype -ResourceName $resourceName -ApiVersion 2016-05-15 -Force#Alternative implementation:# Use resourceId instead of resource type parameters and resource name. # Usage ResourceId allows you to specify the $SubscriptionId instead of using the # subscription ID from Get-AzContext.#$resourceId = "/subscriptions/$SubscriptionId/resourceGroups/$($LabResource.ResourceGroupName)/providers /Microsoft.DevTestLab/labs/$LabName /artifactSources/$ArtifactRepositoryName"#$result = New-AzResource -properties $propertiesObject -ResourceId $resourceId -ApiVersion 2016-05-15 -Force# Check the result.if ($result.Properties .ProvisioningState -eq "Succeeded") { Write-Verbose("Successfully added artifact repository resource '$ArtifactRepositoryDisplayName'")}else { Write-Error("Error adding artifact repository resource '$ArtifactRepositoryDisplayName'")} #Return the newly created resource for use in later scripts.return $result
Parameters
The PowerShell script uses the following parameters:
Parameter | Description |
---|---|
Labnaam | The name of the lab. |
ArtifactRepositoryName | Name for the new artifact repository. The script creates a random name for the repository if not specified. |
ArtifactRepositoryDisplayName | Display name that appears in the lab's list of artifact repositories. |
Repository-URI | URI of the artifact repository, which you copied earlier. |
RepositoryBranch | Repository branch that contains the artifacts. The default value ismain . |
FolderPath | Folder containing the artifacts. The default value is:/Artifacts . |
PersonalAccessToken | Security token to access the repository, which you copied earlier. |
Bron Type | Whether the artifact repository is a VSOGit (Azure Repos) or GitHub repository. |
The repository needs an internal name for identification, which is different from the display name in the Azure portal. You don't see the internal name when you use the Azure portal, but you do when you use Azure REST APIs or Azure PowerShell. The script creates a random name if the implementation command does not specify one.
#Set artifact repository name, if not set by userif ($ArtifactRepositoryName -eq $null){ $ArtifactRepositoryName = "PrivateRepo" + (Get-Random -Maximum 999)}
PowerShell commands
The script uses the following PowerShell commands:
Commando | Notes |
---|---|
Get-AzResource | Get details about the lab, such as its location. You create the artifact repository resource in the same location and under the same resource group as the lab. |
New-AzResource | Adds the Azure resource. There is no specific command for adding artifact repositories. This cmdlet has itResourceId of deSource name InBrontype pair to know what type of resource you want to create. The current script uses theSource name InBrontype pair. |
A good way to find information about the resource name and resource type is to read theAzure REST API-browserwebsite. DevTest-labsSources of Artifactsshows REST APIs for creating and managing DevTest Labs artifact resources. The current script uses the following resource ID:
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{name}
The resource type is whatever is listed after thatproviders
in the URI, except for items enclosed in braces. The resource name is anything between the braces. If you use more than one entry for the resource name, separate each entry with a slash:
$resourcetype = 'Microsoft.DevTestLab/labs/artifactSources'$resourceName = $LabName + '/' + $ArtifactRepositoryName
Run the PowerShell script
Run the PowerShell script, replacing your own values with the sample values inLabnaam
,LabResourceGroupName
,ArtifactRepositoryName
,Repository-URI
,PersonalAccessToken
, InBron Type
:
Set-AzContext -SubscriptionId.\New-DevTestLabArtifactRepository.ps1 -LabName "mydevtestlab" -LabResourceGroupName "mydtlrg" -ArtifactRepositoryName "myteamrepository" -RepositoryUri "https://github.com/myteam/myteamrepository.git" - "1111...." -SourceType "GitHub"
Next steps
- Specify mandatory artifacts for DevTest Labs VMs
- Diagnose artifact defects in the lab
FAQs
How do I add an artifact to my Azure VM? ›
- On the lab's home page, select Add.
- On the Choose a base page, select the type of VM you want.
- On the Create lab resource screen, select Add or Remove Artifacts.
- On the Add artifacts page, select the arrow next to each artifact you want to add to the VM.
Azure Artifacts is free for every organization up to 2 GiB of storage. Once you reach the maximum storage limit, you can no longer upload new artifacts and need to delete some of your existing artifacts or set up billing to increase your storage limit.
How do I create a custom image in Azure DevTest labs? ›In the Azure portal, on your lab's Overview page, select the VM to use for the image from the My virtual machines list. On the VM's Overview page, select Create custom image under Operations in the left navigation. On the Create custom image page, enter a Name and optional Description for the custom image.
Which settings do you need to configure to create a test lab environment using the Azure portal? ›- In the Azure portal, search for and select devtest labs.
- On the DevTest Labs page, select Create. ...
- On the Basic Settings tab, provide the following information: ...
- Optionally, select the Auto-shutdown, Networking, or Tags tabs at the top of the page, and customize those settings.
- Set Up Azure DevOps. ...
- Adding Your Project to Azure DevOps Repos. ...
- Setting the build pipeline. ...
- Configuring the build pipeline. ...
- Configuring the build pipeline build tasks. ...
- Adding the build tasks. ...
- Link build parameters. ...
- Adding final task.
- Add the Publish Pipeline Artifact task.
- Fill out the following fields: Display name: artifact display name. File or directory path: the path of the file or directory to publish. Artifact name: name of the artifact to publish.