From 2e69399cb0babf385b2f94d3be956c6072b3808e Mon Sep 17 00:00:00 2001 From: Bin Du <2686301+northtyphoon@users.noreply.github.com> Date: Tue, 28 Jul 2020 16:17:57 -0700 Subject: [PATCH] Tasks example: add encoded tasks example (#430) * add an ecoded task build sample * update timeout --- samples/dotnetcore/task/ManageTask/Program.cs | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/samples/dotnetcore/task/ManageTask/Program.cs b/samples/dotnetcore/task/ManageTask/Program.cs index 2f5f655..4ad2a96 100644 --- a/samples/dotnetcore/task/ManageTask/Program.cs +++ b/samples/dotnetcore/task/ManageTask/Program.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.IO; using System.Net.Http; using System.Reflection; +using System.Text; using System.Threading.Tasks; using Task=System.Threading.Tasks.Task; @@ -51,7 +52,7 @@ namespace ManageTask Console.WriteLine($" AzureEnvironment: {options.AzureEnvironment.Name}"); Console.WriteLine($" SubscriptionId: {options.SubscriptionId}"); Console.WriteLine($" ResourceGroupName: {options.ResourceGroupName}"); - Console.WriteLine($" RegistyName: {options.RegistryName}"); + Console.WriteLine($" RegistryName: {options.RegistryName}"); Console.WriteLine($"======================================================================"); Console.WriteLine(); @@ -112,6 +113,32 @@ namespace ManageTask Console.WriteLine($"{DateTimeOffset.Now}: Started run: '{run.RunId}'"); + Console.WriteLine($"{DateTimeOffset.Now}: Starting new run with encoded task"); + + string imageName = $"{options.RegistryName}.azurecr.io/weatherservice:latest"; + string taskString = +$@" +version: v1.1.0 +steps: + - build: . -t {imageName} + - push: + timeout: 1800 + - {imageName}"; + + run = await registryClient.Registries.ScheduleRunAsync( + options.ResourceGroupName, + options.RegistryName, + new EncodedTaskRunRequest + { + EncodedTaskContent = Convert.ToBase64String(Encoding.UTF8.GetBytes(taskString)), + SourceLocation = sourceUpload.RelativePath, + Platform = new PlatformProperties(OS.Linux), + Timeout = 60 * 10, // 10 minutes + AgentConfiguration = new AgentProperties(cpu: 2) + }).ConfigureAwait(false); + + Console.WriteLine($"{DateTimeOffset.Now}: Started run: '{run.RunId}'"); + // Poll the run status and wait for completion DateTimeOffset deadline = DateTimeOffset.Now.AddMinutes(10); while (RunInProgress(run.Status)