Created
April 2, 2021 10:36
-
-
Save pizycki/1e6d6f7003aee0bfbb56e6db03b8075f to your computer and use it in GitHub Desktop.
Connect Octopus projects with all tenants and envs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey); | |
var repository = new OctopusRepository(endpoint); | |
var client = new OctopusClient(endpoint); | |
var space = repository.Spaces.FindByName(spaceName); | |
var repositoryForSpace = client.ForSpace(space); | |
var projects = repositoryForSpace.Projects.GetAll().Where(x => !x.IsDisabled); | |
var envs = repositoryForSpace.Environments.GetAll(); | |
foreach (var project in projects) | |
{ | |
var tenants = repositoryForSpace.Tenants.GetAll(); | |
foreach (var tenant in tenants) | |
{ | |
Console.WriteLine( | |
$"Connecting '{project.Name}' project with tenant '{tenant.Name}' for {string.Join(", ", envs.Select(x => x.Name))}"); | |
tenant.ConnectToProjectAndEnvironments(project, envs.ToArray()); | |
repositoryForSpace.Tenants.Modify(tenant); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment