Csharp .Net 5 Azure. Core 1.13.0

Prev Next

Skillable Studio allows execution of scripts against a cloud subscription, as well as executing scripts that do not have a target. Scripts are used in Automated Activities and Life Cycle Actions.

The script environment will be pre-configured for your lab instance. You can use the DefaultAzureCredential class to obtain credentials, which can then be passed other Azure service clients.

var subscriptionId = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
var resourceClient = new ResourcesManagementClient(subscriptionId, new DefaultAzureCredential());
var resourceGroupsClient = resourceClient.ResourceGroups;
Plain text

For details working with the Azure SDK for .NET, please see Microsoft's documentation.

C# scripts in Skillable Studio can use the Using directive at the beginning of a script, to help simplify your code.

//To allow the use of types in a namespace so that you do not have to qualify the use of a type in that namespace:
using System.Text;
Plain text
//To allow you to access static members and nested types of a type without having to qualify the access with the type name.
using static System.Math;
Plain text
//To create an alias for a namespace or a type. This is called a using alias directive.
using Project = PC.MyCompany.Project;

## Interacting with Skillable Studio

Your scripts can communicate success or failure to Skillable Studio in one of two ways.

### Return a Boolean value 

```C#
//do stuff... all good
return true;
Plain text
//do stuff... uh oh
return false;
Plain text
//do stuff... all good
#Set-ActivityResult -Correct -Message 'Nice job'
Plain text
//do stuff... uh oh
#Set-ActivityResult -Incorrect -Message 'Please try again'
Plain text

You can also report the result as a score percentage...

//do stuff... we want to report success and set the score value as 50%
Set-ActivityResult -Percentage .5 -Message "You received half credit"
Plain text

Notifications appear as real-time toast notification in the lab client.

Send-LabNotification 'Hello from Azure CLI'
Plain text

Lab variables are always string name/value pairs. Variable values are scoped to the lab instances and become avaialble within the lab instructions as well as subsequent script executions.

Set-LabVariable -Name 'firstName' -Value 'John'
Plain text

You can "receive" a variable in your script...

#a variable set elsewhere in the lab, but we can use it in our script
var myVariable1 = "@lab.Variable(myVariable1)";
Plain text