Beispiel #1
0
        internal int Run(CommonOptions options)
        {
            log.Verbose($"Calamari Version: {typeof(Program).Assembly.GetInformationalVersion()}");

            if (options.Command.Equals("version", StringComparison.OrdinalIgnoreCase))
            {
                return(0);
            }

            var envInfo = string.Join($"{Environment.NewLine}  ", EnvironmentHelper.SafelyGetEnvironmentInformation());

            log.Verbose($"Environment Information: {Environment.NewLine}  {envInfo}");

            EnvironmentHelper.SetEnvironmentVariable("OctopusCalamariWorkingDirectory", Environment.CurrentDirectory);
            ProxyInitializer.InitializeDefaultProxy();

            using (var container = BuildContainer(options).Build())
            {
                container.Resolve <VariableLogger>().LogVariables();

                var command = container.Resolve <ICommand[]>();
                if (command.Length == 0)
                {
                    throw new CommandException($"Could not find the command {options.Command}");
                }
                if (command.Length > 1)
                {
                    throw new CommandException($"Multiple commands found with the name {options.Command}");
                }

                return(command[0].Execute(options.RemainingArguments.ToArray()));
            }
        }
Beispiel #2
0
        public int Execute(string[] args)
        {
            if (IsVersionCommand(args))
            {
                Console.Write($"Calamari version: {typeof(Program).Assembly.GetInformationalVersion()}");
                return(0);
            }

            Log.Verbose($"Octopus Deploy: Calamari version {typeof(Program).Assembly.GetInformationalVersion()}");
            Log.Verbose($"Environment Information:{Environment.NewLine}" +
                        $"  {string.Join($"{Environment.NewLine}  ", EnvironmentHelper.SafelyGetEnvironmentInformation())}");

            EnvironmentHelper.SetEnvironmentVariable(SpecialVariables.CalamariWorkingDirectory, Environment.CurrentDirectory);

            ProxyInitializer.InitializeDefaultProxy();

            try
            {
                if (command == null)
                {
                    return(PrintHelp(PluginUtils.GetFirstArgument(args)));
                }

                return(command.Execute(args.Skip(1).ToArray()));
            }
            catch (Exception ex)
            {
                return(ConsoleFormatter.PrintError(ex));
            }
        }
Beispiel #3
0
        protected virtual int Run(string[] args)
        {
            try
            {
                SecurityProtocols.EnableAllSecurityProtocols();
                var options = CommonOptions.Parse(args);

                Log.Verbose($"Calamari Version: {GetType().Assembly.GetInformationalVersion()}");

                if (options.Command.Equals("version", StringComparison.OrdinalIgnoreCase))
                {
                    return(0);
                }

                var envInfo = string.Join($"{Environment.NewLine}  ",
                                          EnvironmentHelper.SafelyGetEnvironmentInformation());
                Log.Verbose($"Environment Information: {Environment.NewLine}  {envInfo}");

                EnvironmentHelper.SetEnvironmentVariable("OctopusCalamariWorkingDirectory",
                                                         Environment.CurrentDirectory);
                ProxyInitializer.InitializeDefaultProxy();

                var builder = new ContainerBuilder();
                ConfigureContainer(builder, options);

                using var container = builder.Build();
                container.Resolve <VariableLogger>().LogVariables();

#if DEBUG
                var waitForDebugger = container.Resolve <IVariables>().Get(KnownVariables.Calamari.WaitForDebugger);

                if (string.Equals(waitForDebugger, "true", StringComparison.CurrentCultureIgnoreCase))
                {
                    using var proc = Process.GetCurrentProcess();
                    Log.Info($"Waiting for debugger to attach... (PID: {proc.Id})");

                    while (!Debugger.IsAttached)
                    {
                        Thread.Sleep(1000);
                    }
                }
#endif

                return(ResolveAndExecuteCommand(container, options));
            }
            catch (Exception ex)
            {
                return(ConsoleFormatter.PrintError(ConsoleLog.Instance, ex));
            }
        }
Beispiel #4
0
        void RunWith(
            bool useDefaultProxy,
            string proxyhost,
            int proxyPort,
            string proxyUsername,
            string proxyPassword)
        {
            Environment.SetEnvironmentVariable(EnvironmentVariables.TentacleUseDefaultProxy,
                                               useDefaultProxy.ToString());
            Environment.SetEnvironmentVariable(EnvironmentVariables.TentacleProxyHost, proxyhost);
            Environment.SetEnvironmentVariable(EnvironmentVariables.TentacleProxyPort, proxyPort.ToString());
            Environment.SetEnvironmentVariable(EnvironmentVariables.TentacleProxyUsername, proxyUsername);
            Environment.SetEnvironmentVariable(EnvironmentVariables.TentacleProxyPassword, proxyPassword);

            ProxyInitializer.InitializeDefaultProxy();
        }
Beispiel #5
0
        protected int Execute(string[] args)
        {
            Log.Verbose($"Octopus Deploy: {displayName} version {informationalVersion}");

            ProxyInitializer.InitializeDefaultProxy();
            RegisterCommandAssemblies();

            try
            {
                var action  = GetFirstArgument(args);
                var command = LocateCommand(action);
                if (command == null)
                {
                    return(PrintHelp(action));
                }
                return(command.Execute(args.Skip(1).ToArray()));
            }
            catch (Exception ex)
            {
                return(ConsoleFormatter.PrintError(ex));
            }
        }
        protected async Task <int> Run(string[] args)
        {
            try
            {
                SecurityProtocols.EnableAllSecurityProtocols();
                var options = CommonOptions.Parse(args);

                log.Verbose($"Calamari Version: {GetType().Assembly.GetInformationalVersion()}");

                if (options.Command.Equals("version", StringComparison.OrdinalIgnoreCase))
                {
                    return(0);
                }

                var envInfo = string.Join($"{Environment.NewLine}  ",
                                          EnvironmentHelper.SafelyGetEnvironmentInformation());
                log.Verbose($"Environment Information: {Environment.NewLine}  {envInfo}");

                EnvironmentHelper.SetEnvironmentVariable("OctopusCalamariWorkingDirectory",
                                                         Environment.CurrentDirectory);
                ProxyInitializer.InitializeDefaultProxy();

                var builder = new ContainerBuilder();
                ConfigureContainer(builder, options);
                using (var container = builder.Build())
                {
                    container.Resolve <VariableLogger>().LogVariables();

                    await ResolveAndExecuteCommand(container, options);

                    return(0);
                }
            }
            catch (Exception ex)
            {
                return(ConsoleFormatter.PrintError(ConsoleLog.Instance, ex));
            }
        }