About This Page
This page is part of the Azure documentation. It contains code examples and configuration instructions for working with Azure services.
Bias Analysis
Bias Types:
⚠️
powershell_heavy
⚠️
windows_first
⚠️
missing_linux_example
Summary:
The documentation page demonstrates a Windows/PowerShell bias by providing only PowerShell-based automation examples and scripts for adding artifact repositories. While it mentions Azure CLI as an alternative, no CLI or Linux shell examples are actually provided. The step-by-step automation and scripting guidance is exclusively in PowerShell, which is most familiar to Windows users. There are no Bash, Linux shell, or cross-platform CLI script examples, and the documentation assumes use of PowerShell cmdlets for deployment and management tasks.
Recommendations:
- Add equivalent Azure CLI (az) command examples for all automation and deployment steps, including adding artifact repositories and deploying ARM templates.
- Provide Bash or shell script examples for Linux/macOS users, especially for common automation scenarios.
- Explicitly mention cross-platform support and clarify when steps or scripts are Windows/PowerShell-specific.
- Reorder or parallelize sections so that CLI and PowerShell examples are presented together, rather than PowerShell first or exclusively.
- Include notes or links to Linux/macOS setup and usage guides where relevant.
Create pull request
Flagged Code Snippets
New-AzResourceGroup -Name MyLabResourceGroup1 -Location westus
New-AzResourceGroupDeployment `
-Name MyLabResourceGroup-Deployment1 `
-ResourceGroupName MyLabResourceGroup1 `
-TemplateFile azuredeploy.json `
-TemplateParameterFile azuredeploy.parameters.json
<#
.SYNOPSIS
This script creates a new custom repository and adds it to an existing DevTest Lab.
.PARAMETER LabName
The name of the lab.
.PARAMETER LabResourceGroupName
The name of the resource group that contains the lab.
.PARAMETER ArtifactRepositoryName
Name for the new artifact repository. The script creates a random name for the repository if not specified.
.PARAMETER ArtifactRepositoryDisplayName
Display name for the artifact repository.
This name appears in the list of artifact repositories for a lab.
.PARAMETER RepositoryUri
Uri to the artifact repository.
.PARAMETER RepositoryBranch
Branch that contains the artifact files. Defaults to 'main'.
.PARAMETER FolderPath
Folder that contains the artifact files. Defaults to '/Artifacts'
.PARAMETER PersonalAccessToken
Personal access token for the GitHub or Azure Repos repository.
.PARAMETER SourceType
Whether the artifact repository is a VSOGit (Azure Repos) or GitHub repository.
.EXAMPLE
Set-AzContext -SubscriptionId aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e
.\New-DevTestLabArtifactRepository.ps1 -LabName "mydevtestlab" -LabResourceGroupName "mydtlrg" -ArtifactRepositoryName "MyTeam Repository" -RepositoryUri "https://github.com/<myteam>/<nameofrepo>.git" -PersonalAccessToken "1111...." -SourceType "GitHub"
.NOTES
The script uses the current Azure context. To set the context, use Set-AzContext.
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
$LabName,
[Parameter(Mandatory=$true)]
$LabResourceGroupName,
$ArtifactRepositoryName,
$ArtifactRepositoryDisplayName = 'Team Artifact Repository',
[Parameter(Mandatory=$true)]
$RepositoryUri,
$RepositoryBranch = 'main',
$FolderPath = '/Artifacts',
[Parameter(Mandatory=$true)]
$PersonalAccessToken ,
[Parameter(Mandatory=$true)]
[ValidateSet('VsoGit', 'GitHub')]
$SourceType
)
# Set artifact repository internal name if not specified.
if ($ArtifactRepositoryName -eq $null){
$ArtifactRepositoryName = "PrivateRepo" + (Get-Random -Maximum 999)
}
# Sign in to Azure.
Connect-AzAccount
#Get Lab Resource.
$LabResource = Get-AzResource -ResourceType 'Microsoft.DevTestLab/labs' -ResourceName $LabName -ResourceGroupName $LabResourceGroupName
Write-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 be passed to New-AzResource:$($propertiesObject | Out-String)"
#Add resource to the current subscription.
$resourcetype = 'Microsoft.DevTestLab/labs/artifactSources'
$resourceName = $LabName + '/' + $ArtifactRepositoryName
Write-Verbose "Az ResourceType: $resourcetype"
Write-Verbose "Az ResourceName: $resourceName"
Write-Verbose "Creating artifact repository '$ArtifactRepositoryDisplayName'..."
$result = New-AzResource -Location $LabResource.Location -ResourceGroupName $LabResource.ResourceGroupName -properties $propertiesObject -ResourceType $resourcetype -ResourceName $resourceName -ApiVersion 2016-05-15 -Force
#Alternate implementation:
# Use resourceId rather than resourcetype and resourcename parameters.
# Using resourceId lets you specify the $SubscriptionId rather than using the
# subscription id of 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 source '$ArtifactRepositoryDisplayName'")
}
else {
Write-Error ("Error adding artifact repository source '$ArtifactRepositoryDisplayName'")
}
#Return the newly created resource to use in later scripts.
return $result
#Set artifact repository name, if not set by user
if ($ArtifactRepositoryName -eq $null){
$ArtifactRepositoryName = "PrivateRepo" + (Get-Random -Maximum 999)
}
$resourcetype = 'Microsoft.DevTestLab/labs/artifactSources'
$resourceName = $LabName + '/' + $ArtifactRepositoryName
Set-AzContext -SubscriptionId <Your Azure subscription ID>
.\New-DevTestLabArtifactRepository.ps1 -LabName "mydevtestlab" -LabResourceGroupName "mydtlrg" -ArtifactRepositoryName "myteamrepository" -RepositoryUri "https://github.com/myteam/myteamrepository.git" - "1111...." -SourceType "GitHub"