protected override async Task ExecuteCore() { using (_commandPayload = new CommandPayload(this)) { IJobDefinition def = HelixApi.Job.Define() .WithSource(Source) .WithType(Type) .WithBuild(Build) .WithTargetQueue(TargetQueue); if (CorrelationPayloads != null) { foreach (ITaskItem correlationPayload in CorrelationPayloads) { def = AddCorrelationPayload(def, correlationPayload); } } if (WorkItems != null) { foreach (ITaskItem workItem in WorkItems) { def = AddWorkItem(def, workItem); } } else { Log.LogError("SendHelixJob given no WorkItems to send."); } if (_commandPayload.TryGetPayloadDirectory(out string directory)) { def = def.WithCorrelationPayloadDirectory(directory); } // don't send the job if we have errors if (Log.HasLoggedErrors) { return; } Log.LogMessage(MessageImportance.Normal, "Sending Job..."); ISentJob job = await def.SendAsync(); JobCorrelationId = job.CorrelationId; } }
protected override async Task ExecuteCore(CancellationToken cancellationToken) { if (string.IsNullOrEmpty(AccessToken) && string.IsNullOrEmpty(Creator)) { Log.LogError(FailureCategory.Build, "Creator is required when using anonymous access."); return; } if (!string.IsNullOrEmpty(AccessToken) && !string.IsNullOrEmpty(Creator)) { Log.LogError(FailureCategory.Build, "Creator is forbidden when using authenticated access."); return; } Type = Type.ToLowerInvariant(); cancellationToken.ThrowIfCancellationRequested(); using (_commandPayload = new CommandPayload(this)) { var currentHelixApi = HelixApi; IJobDefinition def = currentHelixApi.Job.Define() .WithType(Type) .WithTargetQueue(TargetQueue) .WithMaxRetryCount(MaxRetryCount); Log.LogMessage($"Initialized job definition with type '{Type}', and target queue '{TargetQueue}'"); if (!string.IsNullOrEmpty(Creator)) { def = def.WithCreator(Creator); Log.LogMessage($"Setting creator to '{Creator}'"); } Log.LogMessage(MessageImportance.High, $"Uploading payloads for Job on {TargetQueue}..."); if (CorrelationPayloads != null) { foreach (ITaskItem correlationPayload in CorrelationPayloads) { def = AddCorrelationPayload(def, correlationPayload); } } if (WorkItems != null) { foreach (ITaskItem workItem in WorkItems) { def = AddWorkItem(def, workItem); } } else { Log.LogError(FailureCategory.Build, "SendHelixJob given no WorkItems to send."); } if (_commandPayload.TryGetPayloadDirectory(out string directory)) { def = def.WithCorrelationPayloadDirectory(directory); } Log.LogMessage(MessageImportance.High, $"Finished uploading payloads for Job on {TargetQueue}..."); if (HelixProperties != null) { foreach (ITaskItem helixProperty in HelixProperties) { def = AddProperty(def, helixProperty); } } // don't send the job if we have errors if (Log.HasLoggedErrors) { return; } Log.LogMessage(MessageImportance.High, $"Sending Job to {TargetQueue}..."); cancellationToken.ThrowIfCancellationRequested(); ISentJob job = await def.SendAsync(msg => Log.LogMessage(msg), cancellationToken); JobCorrelationId = job.CorrelationId; ResultsContainerUri = job.ResultsContainerUri; ResultsContainerReadSAS = job.ResultsContainerReadSAS; cancellationToken.ThrowIfCancellationRequested(); } cancellationToken.ThrowIfCancellationRequested(); }
protected override async Task ExecuteCore(CancellationToken cancellationToken) { if (string.IsNullOrEmpty(AccessToken) && string.IsNullOrEmpty(Creator)) { Log.LogError("Creator is required when using anonymous access."); return; } if (!string.IsNullOrEmpty(AccessToken) && !string.IsNullOrEmpty(Creator)) { Log.LogError("Creator is forbidden when using authenticated access."); return; } Source = Source.ToLowerInvariant(); Type = Type.ToLowerInvariant(); Build = Build.ToLowerInvariant(); cancellationToken.ThrowIfCancellationRequested(); using (_commandPayload = new CommandPayload(this)) { var currentHelixApi = HelixApi; IJobDefinition def = currentHelixApi.Job.Define() .WithSource(Source) .WithType(Type) .WithBuild(Build) .WithTargetQueue(TargetQueue) .WithMaxRetryCount(MaxRetryCount); Log.LogMessage($"Initialized job definition with source '{Source}', type '{Type}', build number '{Build}', and target queue '{TargetQueue}'"); if (!string.IsNullOrEmpty(Creator)) { def = def.WithCreator(Creator); Log.LogMessage($"Setting creator to '{Creator}'"); } if (CorrelationPayloads != null) { foreach (ITaskItem correlationPayload in CorrelationPayloads) { def = AddCorrelationPayload(def, correlationPayload); } } if (WorkItems != null) { foreach (ITaskItem workItem in WorkItems) { def = AddWorkItem(def, workItem); } } else { Log.LogError("SendHelixJob given no WorkItems to send."); } if (_commandPayload.TryGetPayloadDirectory(out string directory)) { def = def.WithCorrelationPayloadDirectory(directory); } if (HelixProperties != null) { foreach (ITaskItem helixProperty in HelixProperties) { def = AddProperty(def, helixProperty); } } if (UsingDownloadResultsFeature) { def = def.WithDefaultResultsContainer(); } // don't send the job if we have errors if (Log.HasLoggedErrors) { return; } Log.LogMessage(MessageImportance.Normal, "Sending Job..."); cancellationToken.ThrowIfCancellationRequested(); ISentJob job = await def.SendAsync(msg => Log.LogMessage(msg)); JobCorrelationId = job.CorrelationId; ResultsContainerUri = job.ResultsContainerUri; ResultsContainerReadSAS = job.ResultsContainerReadSAS; cancellationToken.ThrowIfCancellationRequested(); } string mcUri = await GetMissionControlResultUri(); Log.LogMessage(MessageImportance.High, $"Results will be available from {mcUri}"); cancellationToken.ThrowIfCancellationRequested(); }
protected override async Task ExecuteCore() { if (string.IsNullOrEmpty(AccessToken) && string.IsNullOrEmpty(Creator)) { Log.LogError("Creator is required when using anonymous access."); return; } if (!string.IsNullOrEmpty(AccessToken) && !string.IsNullOrEmpty(Creator)) { Log.LogError("Creator is forbidden when using authenticated access."); return; } using (_commandPayload = new CommandPayload(this)) { var currentHelixApi = HelixApi; IJobDefinition def = currentHelixApi.Job.Define() .WithSource(Source) .WithType(Type) .WithBuild(Build) .WithTargetQueue(TargetQueue) .WithMaxRetryCount(MaxRetryCount); Log.LogMessage($"Initialized job definition with source '{Source}', type '{Type}', build number '{Build}', and target queue '{TargetQueue}'"); if (!string.IsNullOrEmpty(Creator)) { def = def.WithCreator(Creator); Log.LogMessage($"Setting creator to '{Creator}'"); } if (CorrelationPayloads != null) { foreach (ITaskItem correlationPayload in CorrelationPayloads) { def = AddCorrelationPayload(def, correlationPayload); } } if (WorkItems != null) { foreach (ITaskItem workItem in WorkItems) { def = AddWorkItem(def, workItem); } } else { Log.LogError("SendHelixJob given no WorkItems to send."); } if (_commandPayload.TryGetPayloadDirectory(out string directory)) { def = def.WithCorrelationPayloadDirectory(directory); } if (HelixProperties != null) { foreach (ITaskItem helixProperty in HelixProperties) { def = AddProperty(def, helixProperty); } } // don't send the job if we have errors if (Log.HasLoggedErrors) { return; } Log.LogMessage(MessageImportance.Normal, "Sending Job..."); ISentJob job = await def.SendAsync(msg => Log.LogMessage(msg)); JobCorrelationId = job.CorrelationId; } }
protected override async Task ExecuteCore(CancellationToken cancellationToken) { if (string.IsNullOrEmpty(AccessToken) && string.IsNullOrEmpty(Creator)) { Log.LogError(FailureCategory.Build, "Creator is required when using anonymous access."); return; } if (!string.IsNullOrEmpty(AccessToken) && !string.IsNullOrEmpty(Creator)) { Log.LogError(FailureCategory.Build, "Creator is forbidden when using authenticated access."); return; } Type = Type.ToLowerInvariant(); cancellationToken.ThrowIfCancellationRequested(); using (_commandPayload = new CommandPayload(this)) { var currentHelixApi = HelixApi; IJobDefinition def = currentHelixApi.Job.Define() .WithType(Type) .WithTargetQueue(TargetQueue) .WithMaxRetryCount(MaxRetryCount); Log.LogMessage($"Initialized job definition with type '{Type}', and target queue '{TargetQueue}'"); if (!string.IsNullOrEmpty(Creator)) { def = def.WithCreator(Creator); Log.LogMessage($"Setting creator to '{Creator}'"); } if (CorrelationPayloads == null) { Log.LogMessage($"No Correlation Payloads for Job on {TargetQueue} set"); } else { Log.LogMessage($"Adding Correlation Payloads for Job on {TargetQueue}..."); foreach (ITaskItem correlationPayload in CorrelationPayloads) { def = AddCorrelationPayload(def, correlationPayload); } } if (WorkItems != null) { foreach (ITaskItem workItem in WorkItems) { def = AddWorkItem(def, workItem); } } else { Log.LogError(FailureCategory.Build, "SendHelixJob given no WorkItems to send."); } if (_commandPayload.TryGetPayloadDirectory(out string directory)) { def = def.WithCorrelationPayloadDirectory(directory); } if (HelixProperties != null) { foreach (ITaskItem helixProperty in HelixProperties) { def = AddProperty(def, helixProperty); } } def = AddBuildVariableProperty(def, "CollectionUri", "System.CollectionUri"); def = AddBuildVariableProperty(def, "Project", "System.TeamProject"); def = AddBuildVariableProperty(def, "BuildNumber", "Build.BuildNumber"); def = AddBuildVariableProperty(def, "BuildId", "Build.BuildId"); def = AddBuildVariableProperty(def, "DefinitionName", "Build.DefinitionName"); def = AddBuildVariableProperty(def, "DefinitionId", "System.DefinitionId"); def = AddBuildVariableProperty(def, "Reason", "Build.Reason"); var variablesToCopy = new[] { "System.JobId", "System.JobName", "System.JobAttempt", "System.PhaseName", "System.PhaseAttempt", "System.PullRequest.TargetBranch", "System.StageName", "System.StageAttempt", }; foreach (var name in variablesToCopy) { def = AddBuildVariableProperty(def, name, name); } // don't send the job if we have errors if (Log.HasLoggedErrors) { return; } Log.LogMessage(MessageImportance.High, $"Sending Job to {TargetQueue}..."); cancellationToken.ThrowIfCancellationRequested(); // LogMessageFromText will take any string formatted as a canonical error or warning and convert the type of log to this ISentJob job = await def.SendAsync(msg => Log.LogMessageFromText(msg, MessageImportance.Normal), cancellationToken); JobCorrelationId = job.CorrelationId; JobCancellationToken = job.HelixCancellationToken; ResultsContainerUri = job.ResultsContainerUri; ResultsContainerReadSAS = job.ResultsContainerReadSAS; cancellationToken.ThrowIfCancellationRequested(); } cancellationToken.ThrowIfCancellationRequested(); }
protected override async Task ExecuteCore() { using (_commandPayload = new CommandPayload(this)) { var currentHelixApi = HelixApi; if (IsExternal) { Log.LogMessage($"Job is external. Switching to anonymous API."); currentHelixApi = AnonymousApi; var storageApi = new Storage((HelixApi)HelixApi); typeof(HelixApi).GetProperty("Storage").SetValue(AnonymousApi, storageApi); } IJobDefinition def = currentHelixApi.Job.Define() .WithSource(Source) .WithType(Type) .WithBuild(Build) .WithTargetQueue(TargetQueue) .WithMaxRetryCount(MaxRetryCount); Log.LogMessage($"Initialized job definition with source '{Source}', type '{Type}', build number '{Build}', and target queue '{TargetQueue}'"); if (IsExternal) { if (string.IsNullOrEmpty(Creator)) { Log.LogError("The Creator property was left unspecified for an external job. Please set the Creator property or set IsExternal to false."); } else { def.WithCreator(Creator); Log.LogMessage($"Setting creator to '{Creator}'"); } } if (CorrelationPayloads != null) { foreach (ITaskItem correlationPayload in CorrelationPayloads) { def = AddCorrelationPayload(def, correlationPayload); } } if (WorkItems != null) { foreach (ITaskItem workItem in WorkItems) { def = AddWorkItem(def, workItem); } } else { Log.LogError("SendHelixJob given no WorkItems to send."); } if (_commandPayload.TryGetPayloadDirectory(out string directory)) { def = def.WithCorrelationPayloadDirectory(directory); } if (HelixProperties != null) { foreach (ITaskItem helixProperty in HelixProperties) { def = AddProperty(def, helixProperty); } } // don't send the job if we have errors if (Log.HasLoggedErrors) { return; } Log.LogMessage(MessageImportance.Normal, "Sending Job..."); ISentJob job = await def.SendAsync(msg => Log.LogMessage(msg)); JobCorrelationId = job.CorrelationId; } }