Skip to content

Commit

Permalink
Fixes #27, #28, #29, #30, and #31
Browse files Browse the repository at this point in the history
  • Loading branch information
BobJWalker committed Nov 19, 2021
1 parent cae125c commit 29b8754
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 18 deletions.
5 changes: 4 additions & 1 deletion CloneSpace.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ param (
$VariableAccountScopingMatch,
$VariableCertificateScopingMatch,
$VariableTenantTagScopingMatch,
$VariableWorkerPoolScopingMatch,
$InfrastructureEnvironmentScopingMatch,
$InfrastructureTenantScopingMatch,
$InfrastructureTenantTagScopingMatch,
Expand Down Expand Up @@ -135,6 +136,7 @@ $VariableMachineScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "V
$VariableAccountScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "VariableAccountScopingMatch" -ParameterValue $VariableAccountScopingMatch -DefaultValue "SkipUnlessExactMatch" -SingleValueItem $true
$VariableCertificateScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "VariableCertificateScopingMatch" -ParameterValue $VariableCertificateScopingMatch -DefaultValue "SkipUnlessExactMatch" -SingleValueItem $true
$VariableTenantTagScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "VariableTenantTagScopingMatch" -ParameterValue $VariableTenantTagScopingMatch -DefaultValue "SkipUnlessPartialMatch" -SingleValueItem $false
$VariableWorkerPoolScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "VariableWorkerPoolScopingMatch" -ParameterValue $VariableWorkerPoolScopingMatch -DefaultValue "SkipUnlessPartialMatch" -SingleValueItem $true

$InfrastructureEnvironmentScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "InfrastructureEnvironmentScopingMatch" -ParameterValue $InfrastructureEnvironmentScopingMatch -DefaultValue "SkipUnlessPartialMatch" -SingleValueItem $false
$InfrastructureTenantScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "InfrastructureTenantScopingMatch" -ParameterValue $InfrastructureTenantScopingMatch -DefaultValue "SkipUnlessPartialMatch" -SingleValueItem $false
Expand Down Expand Up @@ -188,7 +190,8 @@ $CloneScriptOptions = @{
VariableMachineScopingMatch = $VariableMachineScopingMatch;
VariableAccountScopingMatch = $VariableAccountScopingMatch;
VariableCertificateScopingMatch = $VariableCertificateScopingMatch;
VariableTenantTagScopingMatch = $VariableTenantTagScopingMatch;
VariableWorkerPoolScopingMatch = $VariableWorkerPoolScopingMatch;
VariableTenantTagScopingMatch = $VariableTenantTagScopingMatch;
InfrastructureEnvironmentScopingMatch = $InfrastructureEnvironmentScopingMatch;
InfrastructureTenantScopingMatch = $InfrastructureTenantScopingMatch;
InfrastructureTenantTagScopingMatch = $InfrastructureTenantTagScopingMatch;
Expand Down
4 changes: 4 additions & 0 deletions CloneSpaceProject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ param (
$VariableAccountScopingMatch,
$VariableCertificateScopingMatch,
$VariableTenantTagScopingMatch,
$VariableWorkerPoolScopingMatch,
$InfrastructureEnvironmentScopingMatch,
$InfrastructureTenantScopingMatch,
$InfrastructureTenantTagScopingMatch,
Expand Down Expand Up @@ -89,6 +90,7 @@ $VariableMachineScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "V
$VariableAccountScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "VariableAccountScopingMatch" -ParameterValue $VariableAccountScopingMatch -DefaultValue "SkipUnlessExactMatch" -SingleValueItem $true
$VariableCertificateScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "VariableCertificateScopingMatch" -ParameterValue $VariableCertificateScopingMatch -DefaultValue "SkipUnlessExactMatch" -SingleValueItem $true
$VariableTenantTagScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "VariableTenantTagScopingMatch" -ParameterValue $VariableTenantTagScopingMatch -DefaultValue "SkipUnlessPartialMatch" -SingleValueItem $false
$VariableWorkerPoolScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "VariableWorkerPoolScopingMatch" -ParameterValue $VariableWorkerPoolScopingMatch -DefaultValue "SkipUnlessPartialMatch" -SingleValueItem $true

$InfrastructureEnvironmentScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "InfrastructureEnvironmentScopingMatch" -ParameterValue $InfrastructureEnvironmentScopingMatch -DefaultValue "SkipUnlessPartialMatch" -SingleValueItem $false
$InfrastructureTenantScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "InfrastructureTenantScopingMatch" -ParameterValue $InfrastructureTenantScopingMatch -DefaultValue "SkipUnlessPartialMatch" -SingleValueItem $false
Expand Down Expand Up @@ -722,6 +724,7 @@ Write-OctopusSuccess " -VariableMachineScopingMatch $VariableMachineScopingMatc
Write-OctopusSuccess " -VariableAccountScopingMatch $VariableAccountScopingMatch"
Write-OctopusSuccess " -VariableCertificateScopingMatch $VariableCertificateScopingMatch"
Write-OctopusSuccess " -VariableTenantTagScopingMatch $VariableTenantTagScopingMatch"
Write-OctopusSuccess " -VariableWorkerPoolScopingMatch $VariableWorkerPoolScopingMatch"
Write-OctopusSuccess " -InfrastructureEnvironmentScopingMatch $InfrastructureEnvironmentScopingMatch"
Write-OctopusSuccess " -InfrastructureTenantScopingMatch $InfrastructureTenantScopingMatch"
Write-OctopusSuccess " -InfrastructureTenantTagScopingMatch $InfrastructureTenantTagScopingMatch"
Expand Down Expand Up @@ -778,6 +781,7 @@ $cloneSpaceScript = "$PSScriptRoot\CloneSpace.ps1"
-VariableAccountScopingMatch "$VariableAccountScopingMatch" `
-VariableCertificateScopingMatch "$VariableCertificateScopingMatch" `
-VariableTenantTagScopingMatch "$VariableTenantTagScopingMatch" `
-VariableWorkerPoolScopingMatch "$VariableWorkerPoolScopingMatch" `
-InfrastructureEnvironmentScopingMatch "$InfrastructureEnvironmentScopingMatch" `
-InfrastructureTenantScopingMatch "$InfrastructureTenantScopingMatch" `
-InfrastructureTenantTagScopingMatch "$InfrastructureTenantTagScopingMatch" `
Expand Down
2 changes: 1 addition & 1 deletion src/Cloners/EnvironmentCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function Copy-OctopusEnvironments

$newEnvironment = Save-OctopusEnvironment -environment $copyOfItemToClone -DestinationData $destinationData

$destinationData.EnvironmentList += $newEnvironment
$destinationData.EnvironmentList = Update-OctopusList -itemList $destinationData.EnvironmentList -itemToReplace $newEnvironment
}
else
{
Expand Down
5 changes: 3 additions & 2 deletions src/Cloners/ExternalFeedCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ function Copy-OctopusExternalFeeds

if ($feed.FeedType -eq "AwsElasticContainerRegistry")
{
Throw "Unable to clone $($feed.Name) because it is an AWS Elastic Container Registry. When it is created Octopus will test the AWS credentials. As this is making API calls, I do not have access to said credentials. Without this feed the remainder of your clone will most likely fail. Please create the external feed on the destination and try again. Exiting."
Write-OctopusCritical "Unable to clone $($feed.Name) because it is an AWS Elastic Container Registry. When it is created Octopus will test the AWS credentials. As this is making API calls, I do not have access to said credentials. Without this feed the remainder of your clone will most likely fail. Please create the external feed on the destination and try again. Exiting."
exit 1
}

Write-OctopusChangeLog " - Add $($feed.Name)"

$newExternalFeed = Save-OctopusExternalFeed -ExternalFeed $copyOfItemToClone -DestinationData $destinationData
$destinationData.FeedList += $newExternalFeed
$destinationData.FeedList = Update-OctopusList -itemList $destinationData.FeedList -itemToReplace $newExternalFeed
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cloners/LibraryVariableSetCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function Copy-OctopusLibraryVariableSets
}

$destinationVariableSet = Save-OctopusVariableSet -libraryVariableSet $copySourceVariableSet -destinationData $destinationData
$destinationData.VariableSetList += $destinationVariableSet
$destinationData.VariableSetList = Update-OctopusList -itemList $destinationData.VariableSetList -itemToReplace $destinationVariableSet
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cloners/ProjectGroupCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Copy-OctopusProjectGroups
$copyOfItemToClone = Copy-OctopusObject -ItemToCopy $projectGroup -SpaceId $destinationData.SpaceId -ClearIdValue $true

$newProjectGroup = Save-OctopusProjectGroup -ProjectGroup $copyOfItemToClone -DestinationData $destinationData
$destinationData.ProjectGroupList += $newProjectGroup
$destinationData.ProjectGroupList = Update-OctopusList -itemList $destinationData.ProjectGroupList -itemToReplace $newProjectGroup
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cloners/ScriptModuleCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function Copy-OctopusScriptModules
$copyscriptModule.VariableSetId = $null

$destinationVariableSet = Save-OctopusVariableSet -libraryVariableSet $copyscriptModule -destinationData $destinationData
$destinationData.ScriptModuleList += $destinationVariableSet
$destinationData.ScriptModuleList = Update-OctopusList -itemList $destinationData.ScriptModuleList -itemToReplace $destinationVariableSet
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cloners/TargetCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function Copy-OctopusTargets
Convert-OctopusTargetTenantedDeploymentParticipation -target $copyOfItemToClone

$newOctopusTarget = Save-OctopusTarget -target $copyOfItemToClone -destinationdata $destinationData
$destinationData.TargetList += $newOctopusTarget
$destinationData.TargetList = Update-OctopusList -itemList $destinationData.TargetList -itemToReplace $newOctopusTarget
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cloners/TeamCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function Copy-OctopusSpaceTeams
Write-OctopusChangeLogListDetails -prefixSpaces " " -listType "Members" -idList $copyOfItemToClone.MemberUserIds -destinationList $DestinationData.UserList

$newOctopusTeam = Save-OctopusTeam -team $copyOfItemToClone -destinationData $destinationData
$destinationData.TeamList += $newOctopusTeam
$destinationData.TeamList = Update-OctopusList -itemList $destinationData.TeamList -itemToReplace $newOctopusTeam

Write-OctopusPostCloneCleanUp "Team $($team.Name) was created, external security groups were cleared."
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cloners/TenantCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function Copy-OctopusTenants
$tenantToAdd.ProjectEnvironments = @{}

$destinationTenant = Save-OctopusTenant -Tenant $tenantToAdd -destinationData $destinationData
$destinationData.TenantList += $destinationTenant
$destinationData.TenantList = Update-OctopusList -itemList $destinationData.TenantList -itemToReplace $destinationTenant

if ($CloneScriptOptions.CloneTenantLogos -eq $true)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cloners/TenantTagSetCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function Copy-OctopusTenantTags
$copyOfItemToClone.Tags = @($tags)

$newTenantTagSet = Save-OctopusTenantTagSet -TenantTagSet $copyOfItemToClone -DestinationData $destinationData
$destinationData.TenantTagList += $newTenantTagSet
$destinationData.TenantTagList = Update-OctopusList -itemList $destinationData.TenantTagList -itemToReplace $newTenantTagSet
}

Write-OctopusSuccess "Tenant Tags successfully cloned"
Expand Down
13 changes: 11 additions & 2 deletions src/Cloners/TenantVariableCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,18 @@ function Copy-OctopusTenantLibraryVariables

foreach ($sourceTenantLibraryVariable in $sourceTenantLibraryVariableList)
{
Write-OctopusVerbose "Attempting to match library variable set Id $($sourceTenantLibraryVariable.Name) with destination Id"
$matchingVariableSetId = Convert-SourceIdToDestinationId -SourceList $sourceData.VariableSetList -DestinationList $destinationData.VariableSetList -IdValue $sourceTenantLibraryVariable.Name -ItemName "$($destinationTenant.Name) Library Variable Set" -MatchingOption "ErrorUnlessExactMatch"
$libraryVariableSet = Get-OctopusItemById -ItemList $sourceData.VariableSetList -ItemId $sourceTenantLibraryVariable.Name
$scriptModuleVariableSet = Get-OctopusItemById -ItemList $sourceData.ScriptModuleList -ItemId $sourceTenantLibraryVariable.Name

if ($null -ne $scriptModuleVariableSet)
{
Write-OctopusVerbose "The variable set associated with the tenant is in fact a script module. Skipping ot the next variable set."
continue
}

Write-OctopusVerbose "Attempting to match library variable set Id $($libraryVariableSet.Name) with destination Id"
$matchingVariableSetId = Convert-SourceIdToDestinationId -SourceList $sourceData.VariableSetList -DestinationList $destinationData.VariableSetList -IdValue $sourceTenantLibraryVariable.Name -ItemName "$($libraryVariableSet.Name) Library Variable Set" -MatchingOption "ErrorUnlessExactMatch"

Write-OctopusVerbose "The library variable set id for $($sourceTenantLibraryVariable.Name) on the destination is $matchingVariableSetId"

if ($destinationTenantVariables.LibraryVariables.$($matchingVariableSetId).Templates.Length -eq 0)
Expand Down
26 changes: 24 additions & 2 deletions src/Cloners/VariableSetValuesCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ function Copy-OctopusVariableSetValues
$octopusVariable.Value = $newCertificateId
}

if ($octopusVariable.Type -eq "WorkerPool")
{
Write-OctopusVerbose "$variableName is an worker pool value, converting to a worker pool type"

$newWorkerPoolId = Convert-SourceIdToDestinationId -SourceList $sourceData.WorkerPoolList -DestinationList $destinationData.WorkerPoolList -IdValue $octopusVariable.Value -ItemName "$($octopusVariable.Name) Worker Pool" -MatchingOption $CloneScriptOptions.VariableWorkerPoolScopingMatch

if ($null -eq $newWorkerPoolId -and $CloneScriptOptions.VariableWorkerPoolScopingMatch.ToLower().Trim() -eq "skippunlessexactmatch")
{
continue
}

$octopusVariable.Value = $newWorkerPoolId
}

if ($octopusVariable.IsSensitive -eq $true)
{
$octopusVariable.Value = "Dummy Value"
Expand Down Expand Up @@ -162,8 +176,16 @@ function Copy-OctopusVariableSetValues

if ($CloneScriptOptions.OverwriteExistingVariables.ToString().ToLower().Trim() -eq "addnewwithdefaultvalue")
{
Write-OctopusPostCloneCleanUp "The variable $variableName is a new variable and the OverwriteExistingVariables was set to AddNewWithDefaultValue, adding value set to 'REPLACE ME'"
$octopusVariable.Value = "REPLACE ME"
if ($octopusVariable.Type -eq "String")
{
Write-OctopusPostCloneCleanUp "The variable $variableName is a new variable and the OverwriteExistingVariables was set to AddNewWithDefaultValue, adding value set to 'REPLACE ME'"
$octopusVariable.Value = "REPLACE ME"
}
elseif ($octopusVariable.IsSensitive -eq $false)
{
Write-OctopusPostCloneCleanUp "The variable $variableName is a new variable and the OverwriteExistingVariables was set to AddNewWithDefaultValue, but the variable is not a string, setting it to an empty value"
$octopusVariable.Value = ""
}
}

Write-OctopusChangeLog " - Add $variableName with value $($octopusVariable.Value)"
Expand Down
2 changes: 1 addition & 1 deletion src/Cloners/WorkerCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function Copy-OctopusWorkers
}

$newOctopusWorker = Save-OctopusWorker -worker $copyOfItemToClone -destinationData $destinationData
$destinationData.WorkerList += $newOctopusWorker
$destinationData.WorkerList = Update-OctopusList -itemList $destinationData.WorkerList -itemToReplace $newOctopusWorker
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cloners/WorkerPoolCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function Copy-OctopusWorkerPools
$added = Add-PropertyIfMissing -objectToTest $copyOfItemToClone -propertyName "WorkerPoolType" -propertyValue "StaticWorkerPool"

$newOctopusWorker = Save-OctopusWorkerPool -workerPool $copyOfItemToClone -destinationData $destinationData
$destinationData.WorkerPoolList += $newOctopusWorker
$destinationData.WorkerPoolList = Update-OctopusList -itemList $destinationData.WorkerPoolList -itemToReplace $newOctopusWorker
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Logging.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$currentDate = Get-Date
$currentDateFormatted = $currentDate.ToString("yyyy_MM_dd_HH_mm_ss")
$clonerVersion = "3.2.0"
$clonerVersion = "3.2.2"

$logFolder = "$PSScriptRoot\..\..\"
$logArchiveFolder = "$PSScriptRoot\..\..\logs\archive_$currentDateFormatted"
Expand Down
6 changes: 6 additions & 0 deletions src/Core/Util.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ function Get-OctopusItemById
$ItemList,
$ItemId
)

if ([string]::IsNullOrWhiteSpace($ItemId) -eq $true)
{
Write-OctopusCritical "The sent in item id was $null. Ids should not be null and you will get an error at some point. Stopping this clone so you can fix the issue."
exit 1
}

Write-OctopusVerbose "Attempting to find $ItemId in the item list of $($ItemList.Length) item(s)"

Expand Down

0 comments on commit 29b8754

Please sign in to comment.