public GitHubContext ShallowCopy() { var copy = new GitHubContext(); foreach (var pair in this) { copy[pair.Key] = pair.Value; } return(copy); }
public void InitializeJob(Pipelines.AgentJobRequestMessage message, CancellationToken token) { // Validation Trace.Entering(); ArgUtil.NotNull(message, nameof(message)); ArgUtil.NotNull(message.Resources, nameof(message.Resources)); ArgUtil.NotNull(message.Variables, nameof(message.Variables)); ArgUtil.NotNull(message.Plan, nameof(message.Plan)); _cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token); Global = new GlobalContext(); // Plan Global.Plan = message.Plan; Global.Features = PlanUtil.GetFeatures(message.Plan); // Endpoints Global.Endpoints = message.Resources.Endpoints; // Variables Global.Variables = new Variables(HostContext, message.Variables); // Environment variables shared across all actions Global.EnvironmentVariables = new Dictionary <string, string>(VarUtil.EnvironmentVariableKeyComparer); // Job defaults shared across all actions Global.JobDefaults = new Dictionary <string, IDictionary <string, string> >(StringComparer.OrdinalIgnoreCase); // Job Outputs JobOutputs = new Dictionary <string, VariableValue>(StringComparer.OrdinalIgnoreCase); // Actions environment ActionsEnvironment = message.ActionsEnvironment; // Service container info Global.ServiceContainers = new List <ContainerInfo>(); // Steps context (StepsRunner manages adding the scoped steps context) Global.StepsContext = new StepsContext(); // File table Global.FileTable = new List <String>(message.FileTable ?? new string[0]); // Expression values if (message.ContextData?.Count > 0) { foreach (var pair in message.ContextData) { ExpressionValues[pair.Key] = pair.Value; } } ExpressionValues["secrets"] = Global.Variables.ToSecretsContext(); ExpressionValues["runner"] = new RunnerContext(); ExpressionValues["job"] = new JobContext(); Trace.Info("Initialize GitHub context"); var githubAccessToken = new StringContextData(Global.Variables.Get("system.github.token")); var base64EncodedToken = Convert.ToBase64String(Encoding.UTF8.GetBytes($"x-access-token:{githubAccessToken}")); HostContext.SecretMasker.AddValue(base64EncodedToken); var githubJob = Global.Variables.Get("system.github.job"); var githubContext = new GitHubContext(); githubContext["token"] = githubAccessToken; if (!string.IsNullOrEmpty(githubJob)) { githubContext["job"] = new StringContextData(githubJob); } var githubDictionary = ExpressionValues["github"].AssertDictionary("github"); foreach (var pair in githubDictionary) { githubContext[pair.Key] = pair.Value; } ExpressionValues["github"] = githubContext; Trace.Info("Initialize Env context"); #if OS_WINDOWS ExpressionValues["env"] = new DictionaryContextData(); #else ExpressionValues["env"] = new CaseSensitiveDictionaryContextData(); #endif // Prepend Path Global.PrependPath = new List <string>(); // JobSteps for job ExecutionContext JobSteps = new Queue <IStep>(); // PostJobSteps for job ExecutionContext PostJobSteps = new Stack <IStep>(); // StepsWithPostRegistered for job ExecutionContext StepsWithPostRegistered = new HashSet <Guid>(); // Job timeline record. InitializeTimelineRecord( timelineId: message.Timeline.Id, timelineRecordId: message.JobId, parentTimelineRecordId: null, recordType: ExecutionContextType.Job, displayName: message.JobDisplayName, refName: message.JobName, order: null); // The job timeline record's order is set by server. // Logger (must be initialized before writing warnings). _logger = HostContext.CreateService <IPagingLogger>(); _logger.Setup(_mainTimelineId, _record.Id); // Initialize 'echo on action command success' property, default to false, unless Step_Debug is set EchoOnActionCommand = Global.Variables.Step_Debug ?? false; // Verbosity (from GitHub.Step_Debug). Global.WriteDebug = Global.Variables.Step_Debug ?? false; // Hook up JobServerQueueThrottling event, we will log warning on server tarpit. _jobServerQueue.JobServerQueueThrottling += JobServerQueueThrottling_EventReceived; }