IEnumerable<DeploymentEnvironment> FindEnvironments(OctopusInstance server)
        {
            if (DeployToEnvironmentNames == null || !DeployToEnvironmentNames.Any())
                return Enumerable.Empty<DeploymentEnvironment>();

            var list = new List<DeploymentEnvironment>();
            var environments = Client.List<DeploymentEnvironment>(server.Link("Environments")).Execute();

            foreach (var environmentName in DeployToEnvironmentNames)
            {
                if (string.IsNullOrWhiteSpace(environmentName))
                    continue;

                Log.DebugFormat("Searching for environment '{0}'", environmentName);

                var environment = environments.FirstOrDefault(x => string.Equals(x.Name, environmentName, StringComparison.InvariantCultureIgnoreCase));
                if (environment == null)
                {
                    throw new ArgumentException(string.Format("An environment named '{0}' could not be found.", environmentName));
                }

                Log.InfoFormat("Found environment: {0} [{1}]", environment.Name, environment.Id);

                list.Add(environment);
            }

            return list;
        }
        Project FindProject(OctopusInstance server)
        {
            Log.DebugFormat("Searching for project '{0}'", ProjectName);

            var projects = Client.List<Project>(server.Link("Projects")).Execute();

            var project = projects.FirstOrDefault(x => string.Equals(x.Name, ProjectName, StringComparison.InvariantCultureIgnoreCase));
            if (project == null)
            {
                throw new ArgumentException(string.Format("A project named '{0}' could not be found.", ProjectName));
            }

            Log.InfoFormat("Found project: {0} [{1}]", project.Name, project.Id);

            return project;
        }
Exemplo n.º 3
0
        DeploymentEnvironment FindEnvironment(OctopusInstance server)
        {
            if (string.IsNullOrWhiteSpace(DeployToEnvironmentName))
                return null;

            Log.DebugFormat("Searching for environment '{0}'", DeployToEnvironmentName);

            var environments = Client.List<DeploymentEnvironment>(server.Link("Environments")).Execute();

            var environment = environments.FirstOrDefault(x => string.Equals(x.Name, DeployToEnvironmentName, StringComparison.InvariantCultureIgnoreCase));
            if (environment == null)
            {
                throw new ArgumentException(string.Format("An environment named '{0}' could not be found.", DeployToEnvironmentName));
            }

            Log.InfoFormat("Found environment: {0} [{1}]", environment.Name, environment.Id);

            return environment;
        }