private IJobDefinition AddCorrelationPayload(IJobDefinition def, ITaskItem correlationPayload) { string path = correlationPayload.GetMetadata("FullPath"); string uri = correlationPayload.GetMetadata("Uri"); if (!string.IsNullOrEmpty(uri)) { Log.LogMessage(MessageImportance.Low, $"Adding Correlation Payload URI '{uri}'"); return(def.WithCorrelationPayloadUris(new Uri(uri))); } if (Directory.Exists(path)) { string includeDirectoryNameStr = correlationPayload.GetMetadata("IncludeDirectoryName"); bool.TryParse(includeDirectoryNameStr, out bool includeDirectoryName); Log.LogMessage(MessageImportance.Low, $"Adding Correlation Payload Directory '{path}'"); return(def.WithCorrelationPayloadDirectory(path, includeDirectoryName)); } if (File.Exists(path)) { Log.LogMessage(MessageImportance.Low, $"Adding Correlation Payload Archive '{path}'"); return(def.WithCorrelationPayloadArchive(path)); } Log.LogError($"Correlation Payload '{path}' not found."); return(def); }
private IJobDefinition AddCorrelationPayload(IJobDefinition def, ITaskItem correlationPayload) { string path = correlationPayload.GetMetadata("FullPath"); if (!Directory.Exists(path)) { Log.LogError($"Correlation Payload Directory '{path}' not found."); return(def); } return(def.WithCorrelationPayloadDirectory(path)); }
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; } }
private IJobDefinition AddCorrelationPayload(IJobDefinition def, ITaskItem correlationPayload) { string path = correlationPayload.GetMetadata("FullPath"); if (Directory.Exists(path)) { Log.LogMessage(MessageImportance.Low, $"Adding Correlation Payload Directory '{path}'"); return(def.WithCorrelationPayloadDirectory(path)); } else if (File.Exists(path)) { Log.LogMessage(MessageImportance.Low, $"Adding Correlation Payload Archive '{path}'"); return(def.WithCorrelationPayloadArchive(path)); } else { Log.LogError($"Correlation Payload '{path}' not found."); return(def); } }
private IJobDefinition AddCorrelationPayload(IJobDefinition def, ITaskItem correlationPayload) { string path = correlationPayload.GetMetadata("FullPath"); string uri = correlationPayload.GetMetadata("Uri"); string destination = correlationPayload.GetMetadata("Destination") ?? ""; if (!string.IsNullOrEmpty(uri)) { Log.LogMessage(MessageImportance.Low, $"Adding Correlation Payload URI '{uri}', destination '{destination}'"); if (!string.IsNullOrEmpty(destination)) { return(def.WithCorrelationPayloadUris(new Dictionary <Uri, string>() { { new Uri(uri), destination } })); } else { return(def.WithCorrelationPayloadUris(new Uri(uri))); } } if (Directory.Exists(path)) { string includeDirectoryNameStr = correlationPayload.GetMetadata("IncludeDirectoryName"); bool.TryParse(includeDirectoryNameStr, out bool includeDirectoryName); Log.LogMessage(MessageImportance.Low, $"Adding Correlation Payload Directory '{path}', destination '{destination}'"); return(def.WithCorrelationPayloadDirectory(path, includeDirectoryName, destination)); } if (File.Exists(path)) { Log.LogMessage(MessageImportance.Low, $"Adding Correlation Payload Archive '{path}', destination '{destination}'"); return(def.WithCorrelationPayloadArchive(path, destination)); } Log.LogError(FailureCategory.Build, $"Correlation Payload '{path}' not found."); return(def); }
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; } }
private IJobDefinition AddCorrelationPayload(IJobDefinition def, ITaskItem correlationPayload) { string path = correlationPayload.GetMetadata(MetadataNames.FullPath); string uri = correlationPayload.GetMetadata(MetadataNames.Uri); string destination = correlationPayload.GetMetadata(MetadataNames.Destination) ?? ""; if (!string.IsNullOrEmpty(uri)) { Log.LogMessage(MessageImportance.Low, $"Adding Correlation Payload URI '{uri}', destination '{destination}'"); if (!string.IsNullOrEmpty(destination)) { return(def.WithCorrelationPayloadUris(new Dictionary <Uri, string>() { { new Uri(uri), destination } })); } else { return(def.WithCorrelationPayloadUris(new Uri(uri))); } } if (Directory.Exists(path)) { string includeDirectoryNameStr = correlationPayload.GetMetadata(MetadataNames.IncludeDirectoryName); if (!bool.TryParse(includeDirectoryNameStr, out bool includeDirectoryName)) { includeDirectoryName = false; } Log.LogMessage( MessageImportance.Low, $"Adding Correlation Payload Directory '{path}', destination '{destination}'" ); return(def.WithCorrelationPayloadDirectory(path, includeDirectoryName, destination)); } if (File.Exists(path)) { string asArchiveStr = correlationPayload.GetMetadata(MetadataNames.AsArchive); if (!bool.TryParse(asArchiveStr, out bool asArchive)) { // With no other information, default to true, since that was the previous behavior // before we added the option asArchive = true; } if (asArchive) { Log.LogMessage( MessageImportance.Low, $"Adding Correlation Payload Archive '{path}', destination '{destination}'" ); return(def.WithCorrelationPayloadArchive(path, destination)); } Log.LogMessage( MessageImportance.Low, $"Adding Correlation Payload File '{path}', destination '{destination}'" ); return(def.WithCorrelationPayloadFiles(path)); } Log.LogError(FailureCategory.Build, $"Correlation Payload '{path}' not found."); return(def); }
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; } }