diff --git a/src/Microsoft.DotNet.Helix/JobSender/JobDefinition.cs b/src/Microsoft.DotNet.Helix/JobSender/JobDefinition.cs index 96f1778ab9f..87364e05c4d 100644 --- a/src/Microsoft.DotNet.Helix/JobSender/JobDefinition.cs +++ b/src/Microsoft.DotNet.Helix/JobSender/JobDefinition.cs @@ -154,6 +154,15 @@ public async Task SendAsync(Action log = null) var (queueId, dockerTag, queueAlias) = ParseQueueId(TargetQueueId); + try + { + QueueInfo queueInfo = await HelixApi.Information.QueueInfoAsync(queueId, CancellationToken.None); + } + // 404 = this queue does not exist, or did and was removed. + catch (RestApiException ex) when ((int)ex.Response?.StatusCode == 404) + { + throw new ArgumentException($"Helix API does not contain an entry for {queueId}"); + } IBlobContainer storageContainer = await storage.GetContainerAsync(TargetContainerName, queueId); var jobList = new List(); diff --git a/src/Microsoft.DotNet.Helix/Sdk/HelixTask.cs b/src/Microsoft.DotNet.Helix/Sdk/HelixTask.cs index 26973a96ccd..c5e12bfdbe0 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/HelixTask.cs +++ b/src/Microsoft.DotNet.Helix/Sdk/HelixTask.cs @@ -23,6 +23,13 @@ public abstract class HelixTask : BaseTask, ICancelableTask /// public string AccessToken { get; set; } + /// + /// If , fail when posting jobs to non-existent queues; If allow it and print a warning. + /// Note if an MSBuild sequence starts and waits on jobs, and none are started, this will still fail. + /// Defined on HelixTask so the catch block around Execute() can know about it. + /// + public bool FailOnMissingTargetQueue { get; set; } = true; + protected IHelixApi HelixApi { get; private set; } protected IHelixApi AnonymousApi { get; private set; } @@ -65,6 +72,17 @@ public sealed override bool Execute() // Canceled return false; } + catch (ArgumentException argEx) when (argEx.Message.StartsWith("Helix API does not contain an entry ")) + { + if (FailOnMissingTargetQueue) + { + Log.LogError(argEx.Message); + } + else + { + Log.LogWarning($"{argEx.Message} (FailOnMissingTargetQueue is false, so this is just a warning.)"); + } + } catch (Exception ex) { Log.LogErrorFromException(ex, true, true, null); diff --git a/src/Microsoft.DotNet.Helix/Sdk/Readme.md b/src/Microsoft.DotNet.Helix/Sdk/Readme.md index bffa82cb6e0..d5f27bd5c75 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/Readme.md +++ b/src/Microsoft.DotNet.Helix/Sdk/Readme.md @@ -1,9 +1,9 @@ # Microsoft.DotNet.Helix.Sdk -This Package provides Helix Job sending functionality from an MSBuild project file. +This Package provides Helix Job-sending functionality from an MSBuild project file. ## Examples -Each of the following examples require dotnet-cli >= 2.1.300 and need the following files in a directory at or above the example project's directory. +Each of the following examples require dotnet-cli >= 3.1.x, and need the following files in a directory at or above the example project's directory. #### global.json ```json { @@ -108,13 +108,21 @@ Given a local folder `$(TestFolder)` containing `runtests.cmd`, this will run `r Windows.10.Amd64.Open + + false + - Ubuntu.1804.Amd64.Open;Ubuntu.1604.Amd64.Open + Ubuntu.1804.Amd64.Open;Ubuntu.1604.Amd64.Open;(Alpine.39.Amd64)Ubuntu.1804.Amd64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:alpine-3.9-helix-bfcd90a-20200123191053 true @@ -131,19 +139,7 @@ Given a local folder `$(TestFolder)` containing `runtests.cmd`, this will run `r true false - - false - - @@ -175,7 +171,6 @@ Given a local folder `$(TestFolder)` containing `runtests.cmd`, this will run `r - + true @@ -46,6 +49,7 @@