Create your own artifacts for Azure DevTest Labs

In previous post told you the new Azure DevTest Labs service (still in preview) , which allows you to create test and development environments for your team. One of the options within the lab is the possibility to enable your own artifacts (applications and tasks) to be available for machines that users can create. Today I‘m going to talk about how to create this repository on GitHub and how you can use it from the service.

Create a repository on GitHub

The first thing you need is a git repository. This can be on GitHub or also on Visual Studio Team Services. This guide can be you very useful if you don’t know how to work with git, but I will explain step by step how to build what you need for this scenario.
To connect with GitHub, you need to install a client for your operating system. In my case I’m using GitHub Desktop. With it you can create a new repository via the Create option.
Create GitHub repository - Azure DevTest Labs
Create GitHub repository – Azure DevTest Labs

A new element  will be shown, representing the repository just created, and you can select it in order to open the git terminal or Windows Explorer to start creating the structure. Open Explorer and create a folder called artifacts.

GitHub Desktop - Repository - Open in Explorer
GitHub Desktop – Repository – Open in Explorer

Inside that folder,  you’re going to create a directory for each artifact you want to expose. For example, create an artifact that allows you to install Skype. Create a folder called windows-skype within artifacts.

Create a new artifact windows-skype
Create a new artifact windows-skype

We are going to follow the example of the product team and install the tools using Chocolatey to manage our packages.To do so, we will need two scripts, which I’ve recovered from the Azure/azure-devtestlab repository: startChocolatey.ps1 and ChocolateyPackageInstaller.ps1. The first one receives as argument the packages to install, create a user who execute the script as an administrator and launch the second one which receives the name of the packages. It will install chocolatey and request the packages received as a parameter. Save these two files in the folder windows-skype. Finally, you need a file called Artifactfile.json, which should have the following structure in JSON:

{
  "$schema": "https://raw.githubusercontent.com/Azure/azure-devtestlab/master/schemas/2015-01-01/dtlArtifacts.json",
  "title": "Skype",
  "description": "Installs Skype using the Chocolatey package manager.",
  "tags": [
    "Windows",
    "Skype"
    
  ],
  "iconUri": "https://chocolatey.org/content/packageimages/skype.7.15.0.102.png",
  "targetOsType": "Windows",
  "runCommand": {
    "commandToExecute": "powershell.exe -executionpolicy bypass -File startChocolatey.ps1 -PackageList skype"
  }
}
  • $schema: sets the file schema.
  • title: the name of the artifact that you want to appear on the list.
  • description: description of the artifact.
  • tags: tags that identify the artifact.
  • iconUri: icon to be displayed in the list of elements.
  • targetOsType: since it is possible to install both Windows and Linux machines, it is necessary to indicate for which type of machines this artifact is intended.
  • runCommand -> commandToExecute: this is the command that will be launched when this artifact in the list is selected. As you can see, it makes a call to the script startChocolatey.ps1 passing the list of packages you want to install.

Finally, you have to upload the changes to your repository. To do this simply go to GitHub desktop, click on the tab Changes and commit to master.

Azure DevTest Labs - Commit artifact
Azure DevTest Labs – Commit artifact

Click on Publish to create the repository on GitHub.

GitHub Desktop - Publish
GitHub Desktop – Publish

If you access your profile (https://github.com/USERNAME) you will see that your new repository is ready.

Github profile - Popular repositories
Github profile – Popular repositories

Associate your repository with Azure DevTest Labs

Now you have your own repository on GitHub that can be used during the creation of your virtual machines. The last step is to connect it with your Azure DevTest Labs account so that it will appear as an option in the list of artifacts.

If you have not yet created an environment of DevTest Labs, you can follow the steps in the previous post. You will see that there is a section called Artifact Repository. Click on it to set up yours.

Azure DevTest Labs - Artifact Repository
Azure DevTest Labs – Artifact Repository
  • Name: name of the repository of artifacts.
  • Git Clone Uri: this is the URL that is used to clone a Git repository, you can find it on the page of your repository.
  • Folder Path: the root folder where all artifacts are. In this example I‘ve called artifacts.
  • Branch: the branch in git where changes are being made to generate this repository. To simplify the process, this post has been used directly the master branch.
  • Personal Access Token: to access a repository from github, you need a token. You can generate one from https://github.com/settings/tokens, click on Generate token and leave the scope by default for this scenario. Copy the generated token and paste it in this section.

Create a virtual machine with you artifact

To check that your artifacts are working correctly, you can create a virtual machine that you associate your new artifactSelect Add Lab VM, click on the Artifacts section and you‘ll see that in addition to the official elements you have a new one that comes from your repository.

Lab VM - Artifacts - Skype - My own artifacts
Lab VM – Artifacts – Skype – My own artifacts

If during creation you can see that your artifacts have not been installed correctly or some error occurred during the process,there is a log that you can use to know the final result of the installation. Select the virtual machine and go to Settings > Extensions > customScriptArtifact.

Azure DevTest Labs - extensions - customScriptArtifact
Azure DevTest Labs – extensions – customScriptArtifact

Happy weekend!