public bool TryProcessCommand(IExecutionContext context, string input) { if (string.IsNullOrEmpty(input)) { return(false); } // TryParse input to Command Command command; if (!Command.TryParse(input, out command)) { // if parse fail but input contains ##vso, print warning with DOC link if (input.IndexOf("##vso") >= 0) { context.Warning(StringUtil.Loc("CommandKeywordDetected", input)); } return(false); } IWorkerCommandExtension extension; if (_commandExtensions.TryGetValue(command.Area, out extension)) { // process logging command in serialize oreder. lock (_commandSerializeLock) { try { extension.ProcessCommand(context, command); } catch (Exception ex) { context.Error(StringUtil.Loc("CommandProcessFailed", input)); context.Error(ex); context.CommandResult = TaskResult.Failed; } finally { // trace the ##vso command as long as the command is not a ##vso[task.debug] command. if (!(string.Equals(command.Area, "task", StringComparison.OrdinalIgnoreCase) && string.Equals(command.Event, "debug", StringComparison.OrdinalIgnoreCase))) { context.Debug($"Processed: {input}"); } } } } else { context.Warning(StringUtil.Loc("CommandNotFound", command.Area)); } return(true); }
public bool TryProcessCommand(IExecutionContext context, string input) { if (string.IsNullOrEmpty(input)) { return(false); } // TryParse input to Command Command command; if (!Command.TryParse(input, out command)) { // if parse fail but input contains ##vso, print warning with DOC link if (input.IndexOf("##vso") >= 0) { context.Warning($"'{input}' contains logging command keyword '##vso'. TODO: aka link to command DOC."); } return(false); } Trace.Info($"Process logging commnad ##vso[{command.Area}.{command.Event}]"); ICommandExtension handler; if (_commandHandlers.TryGetValue(command.Area, out handler)) { // process logging command in serialize oreder. lock (_commandSerializeLock) { try { handler.ProcessCommand(context, command); context.Debug($"Processed logging command: {input}"); } catch (Exception ex) { context.Error(ex); context.Error($"Unable to process command {command} successfully."); context.CommandResult = TaskResult.Failed; } } } else { context.Warning(StringUtil.Loc("CommandNotFound", command.Area)); } return(true); }
public bool TryProcessCommand(IExecutionContext context, string input) { if (string.IsNullOrEmpty(input)) { return(false); } // TryParse input to Command Command command; if (!Command.TryParse(input, out command)) { // if parse fail but input contains ##vso, print warning with DOC link if (input.IndexOf("##vso") >= 0) { context.Warning(StringUtil.Loc("CommandKeywordDetected", input)); } return(false); } IWorkerCommandExtension extension; if (_commandExtensions.TryGetValue(command.Area, out extension)) { // process logging command in serialize oreder. lock (_commandSerializeLock) { try { context.Debug($"Processing: {input}"); extension.ProcessCommand(context, command); } catch (Exception ex) { context.Error(StringUtil.Loc("CommandProcessFailed", input)); context.Error(ex); context.CommandResult = TaskResult.Failed; } } } else { context.Warning(StringUtil.Loc("CommandNotFound", command.Area)); } return(true); }
public bool TryProcessCommand(IExecutionContext context, string input) { ArgUtil.NotNull(context, nameof(context)); if (string.IsNullOrEmpty(input)) { return(false); } // TryParse input to Command Command command; var unescapePercents = AgentKnobs.DecodePercents.GetValue(context).AsBoolean(); if (!Command.TryParse(input, unescapePercents, out command)) { // if parse fail but input contains ##vso, print warning with DOC link if (input.IndexOf("##vso") >= 0) { context.Warning(StringUtil.Loc("CommandKeywordDetected", input)); } return(false); } IWorkerCommandExtension extension = null; if (_invokePluginInternalCommand && string.Equals(command.Area, _pluginInternalCommandExtensions.CommandArea, StringComparison.OrdinalIgnoreCase)) { extension = _pluginInternalCommandExtensions; } if (extension != null || _commandExtensions.TryGetValue(command.Area, out extension)) { if (!extension.SupportedHostTypes.HasFlag(context.Variables.System_HostType)) { context.Error(StringUtil.Loc("CommandNotSupported", command.Area, context.Variables.System_HostType)); context.CommandResult = TaskResult.Failed; return(false); } // process logging command in serialize oreder. lock (_commandSerializeLock) { try { extension.ProcessCommand(context, command, restrictionPolicy); } catch (Exception ex) { context.Error(StringUtil.Loc("CommandProcessFailed", input)); context.Error(ex); context.CommandResult = TaskResult.Failed; } finally { // trace the ##vso command as long as the command is not a ##vso[task.debug] command. if (!(string.Equals(command.Area, "task", StringComparison.OrdinalIgnoreCase) && string.Equals(command.Event, "debug", StringComparison.OrdinalIgnoreCase))) { context.Debug($"Processed: {input}"); } } } } else { context.Warning(StringUtil.Loc("CommandNotFound", command.Area)); } // Only if we've successfully parsed do we show this warning if (AgentKnobs.DecodePercents.GetValue(context).AsString() == "" && input.Contains("%25")) { context.Warning("%25 detected in ##vso command. In March 2021, the agent command parser will be updated to unescape this to %. To opt out of this behavior, set a job level variable DECODE_PERCENTS to false. Setting to true will force this behavior immediately. More information can be found at https://github.com/microsoft/azure-pipelines-agent/blob/master/docs/design/percentEncoding.md"); } return(true); }
public bool TryProcessCommand(IExecutionContext context, string input) { ArgUtil.NotNull(context, nameof(context)); if (string.IsNullOrEmpty(input)) { return(false); } // TryParse input to Command Command command; if (!Command.TryParse(input, out command)) { // if parse fail but input contains ##vso, print warning with DOC link if (input.IndexOf("##vso") >= 0) { context.Warning(StringUtil.Loc("CommandKeywordDetected", input)); } return(false); } IWorkerCommandExtension extension = null; if (_invokePluginInternalCommand && string.Equals(command.Area, _pluginInternalCommandExtensions.CommandArea, StringComparison.OrdinalIgnoreCase)) { extension = _pluginInternalCommandExtensions; } if (extension != null || _commandExtensions.TryGetValue(command.Area, out extension)) { if (!extension.SupportedHostTypes.HasFlag(context.Variables.System_HostType)) { context.Error(StringUtil.Loc("CommandNotSupported", command.Area, context.Variables.System_HostType)); context.CommandResult = TaskResult.Failed; return(false); } // process logging command in serialize oreder. lock (_commandSerializeLock) { try { extension.ProcessCommand(context, command, restrictionPolicy); } catch (Exception ex) { context.Error(StringUtil.Loc("CommandProcessFailed", input)); context.Error(ex); context.CommandResult = TaskResult.Failed; } finally { // trace the ##vso command as long as the command is not a ##vso[task.debug] command. if (!(string.Equals(command.Area, "task", StringComparison.OrdinalIgnoreCase) && string.Equals(command.Event, "debug", StringComparison.OrdinalIgnoreCase))) { context.Debug($"Processed: {input}"); } } } } else { context.Warning(StringUtil.Loc("CommandNotFound", command.Area)); } return(true); }
public bool TryProcessCommand(IExecutionContext context, string input) { if (string.IsNullOrEmpty(input)) { return(false); } // TryParse input to Command Command command; if (!Command.TryParse(input, out command)) { // if parse fail but input contains ##vso, print warning with DOC link if (input.IndexOf("##vso") >= 0) { context.Warning(StringUtil.Loc("CommandKeywordDetected", input)); } return(false); } var disablePlugin = context.Variables.GetBoolean("VSTS_DISABLEPLUGINCOMMAND") ?? StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable("VSTS_DISABLEPLUGINCOMMAND")); var agentPlugins = HostContext.GetService <IAgentPluginManager>(); if (!disablePlugin && agentPlugins.GetPluginCommad(command.Area, command.Event) != null) { agentPlugins.ProcessCommand(context, command); } else if (_commandExtensions.TryGetValue(command.Area, out IWorkerCommandExtension extension)) { if (!extension.SupportedHostTypes.HasFlag(context.Variables.System_HostType)) { context.Error(StringUtil.Loc("CommandNotSupported", command.Area, context.Variables.System_HostType)); context.CommandResult = TaskResult.Failed; return(false); } // process logging command in serialize oreder. lock (_commandSerializeLock) { try { extension.ProcessCommand(context, command); } catch (Exception ex) { context.Error(StringUtil.Loc("CommandProcessFailed", input)); context.Error(ex); context.CommandResult = TaskResult.Failed; } finally { // trace the ##vso command as long as the command is not a ##vso[task.debug] command. if (!(string.Equals(command.Area, "task", StringComparison.OrdinalIgnoreCase) && string.Equals(command.Event, "debug", StringComparison.OrdinalIgnoreCase))) { context.Debug($"Processed: {input}"); } } } } else { context.Warning(StringUtil.Loc("CommandNotFound", command.Area)); } return(true); }