Skip to content

Commit

Permalink
Fixing issue with the new overwrite variable option, added clone logo…
Browse files Browse the repository at this point in the history
…s params
  • Loading branch information
BobJWalker committed Nov 16, 2021
1 parent 7a965b9 commit 1bdd4dd
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 20 deletions.
18 changes: 12 additions & 6 deletions CloneSpace.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ param (
$CloneTeamUserRoleScoping,
$CloneProjectChannelRules,
$CloneProjectVersioningReleaseCreationSettings,
$CloneProjectDeploymentProcess,
$IgnoreVersionCheckResult,
$SkipPausingWhenIgnoringVersionCheckResult,
$CloneTenantVariables,
$CloneProjectDeploymentProcess,
$CloneProjectLogos,
$CloneTenantLogos,
$CloneTenantVariables,
$ProcessEnvironmentScopingMatch,
$ProcessChannelScopingMatch,
$ProcessTenantTagScopingMatch,
Expand All @@ -53,6 +53,8 @@ param (
$InfrastructureTenantScopingMatch,
$InfrastructureTenantTagScopingMatch,
$ProcessCloningOption,
$IgnoreVersionCheckResult,
$SkipPausingWhenIgnoringVersionCheckResult,
$WhatIf
)

Expand Down Expand Up @@ -107,7 +109,9 @@ $CloneProjectRunbooks = Test-OctopusTrueFalseParameter -parameterValue $ClonePro
$CloneTeamUserRoleScoping = Test-OctopusTrueFalseParameter -parameterValue $CloneTeamUserRoleScoping -parameterName "CloneTeamUserRoleScoping" -defaultValue $false
$CloneProjectChannelRules = Test-OctopusTrueFalseParameter -parameterValue $CloneProjectChannelRules -parameterName "CloneProjectChannelRules" -defaultValue $false
$CloneProjectVersioningReleaseCreationSettings = Test-OctopusTrueFalseParameter -parameterValue $CloneProjectVersioningReleaseCreationSettings -parameterName "CloneProjectVersioningReleaseCreationSettings" -defaultValue $false
$CloneProjectDeploymentProcess = Test-OctopusTrueFalseParameter -parameterValue $CloneProjectDeploymentProcess -parameterName "CloneProjectDeploymentProcess" -defaultValue $false
$CloneProjectDeploymentProcess = Test-OctopusTrueFalseParameter -parameterValue $CloneProjectDeploymentProcess -parameterName "CloneProjectDeploymentProcess" -defaultValue $true
$CloneProjectLogos = Test-OctopusTrueFalseParameter -parameterValue $CloneProjectLogos -parameterName "CloneProjectLogos" -defaultValue $true
$CloneTenantLogos = Test-OctopusTrueFalseParameter -parameterValue $CloneTenantLogos -parameterName "CloneTenantLogos" -defaultValue $true
$CloneTenantVariables = Test-OctopusTrueFalseParameter -parameterValue $CloneTenantVariables -parameterName "CloneTenantVariables" -defaultValue $false

$RunbooksToClone = Test-OctopusNewListParameter -parameterValue $RunbooksToClone -parameterName "RunbooksToClone"
Expand Down Expand Up @@ -172,7 +176,9 @@ $CloneScriptOptions = @{
CloneProjectChannelRules = $CloneProjectChannelRules;
CloneProjectVersioningReleaseCreationSettings = $CloneProjectVersioningReleaseCreationSettings;
CloneProjectDeploymentProcess = $CloneProjectDeploymentProcess;
CloneTenantVariables = $CloneTenantVariables;
CloneTenantVariables = $CloneTenantVariables;
CloneTenantLogos = $CloneTenantLogos;
CloneProjectLogos = $CloneProjectLogos;
ProcessEnvironmentScopingMatch = $ProcessEnvironmentScopingMatch;
ProcessChannelScopingMatch = $ProcessChannelScopingMatch;
ProcessTenantTagScopingMatch = $ProcessTenantTagScopingMatch;
Expand Down
12 changes: 10 additions & 2 deletions CloneSpaceProject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ param (
$CloneTeamUserRoleScoping,
$CloneProjectChannelRules,
$CloneProjectVersioningReleaseCreationSettings,
$CloneProjectDeploymentProcess,
$CloneProjectDeploymentProcess,
$CloneProjectLogos,
$CloneTenantLogos,
$CloneTenantVariables,
$ClonePackages,
$ProcessEnvironmentScopingMatch,
Expand Down Expand Up @@ -67,7 +69,9 @@ $CloneProjectRunbooks = Test-OctopusTrueFalseParameter -parameterValue $ClonePro
$CloneTeamUserRoleScoping = Test-OctopusTrueFalseParameter -parameterValue $CloneTeamUserRoleScoping -parameterName "CloneTeamUserRoleScoping" -defaultValue $false
$CloneProjectChannelRules = Test-OctopusTrueFalseParameter -parameterValue $CloneProjectChannelRules -parameterName "CloneProjectChannelRules" -defaultValue $false
$CloneProjectVersioningReleaseCreationSettings = Test-OctopusTrueFalseParameter -parameterValue $CloneProjectVersioningReleaseCreationSettings -parameterName "CloneProjectVersioningReleaseCreationSettings" -defaultValue $false
$CloneProjectDeploymentProcess = Test-OctopusTrueFalseParameter -parameterValue $CloneProjectDeploymentProcess -parameterName "CloneProjectDeploymentProcess" -defaultValue $false
$CloneProjectDeploymentProcess = Test-OctopusTrueFalseParameter -parameterValue $CloneProjectDeploymentProcess -parameterName "CloneProjectDeploymentProcess" -defaultValue $true
$CloneProjectLogos = Test-OctopusTrueFalseParameter -parameterValue $CloneProjectLogos -parameterName "CloneProjectLogos" -defaultValue $true
$CloneTenantLogos = Test-OctopusTrueFalseParameter -parameterValue $CloneTenantLogos -parameterName "CloneTenantLogos" -defaultValue $true
$CloneTenantVariables = Test-OctopusTrueFalseParameter -parameterValue $CloneTenantVariables -parameterName "CloneTenantVariables" -defaultValue $false
$ClonePackages = Test-OctopusTrueFalseParameter -parameterValue $ClonePackages -parameterName "ClonePackages" -defaultValue $false

Expand Down Expand Up @@ -692,6 +696,8 @@ Write-OctopusSuccess " -CloneProjectChannelRules $CloneProjectChannelRules"
Write-OctopusSuccess " -CloneProjectRunbooks $CloneProjectRunbooks"
Write-OctopusSuccess " -CloneProjectVersioningReleaseCreationSettings $CloneProjectVersioningReleaseCreationSettings"
Write-OctopusSuccess " -CloneProjectDeploymentProcess $CloneProjectDeploymentProcess"
Write-OctopusSuccess " -CloneProjectLogos $CloneProjectLogos"
Write-OctopusSuccess " -CloneTenantLogos $CloneTenantLogos"
Write-OctopusSuccess " -IgnoreVersionCheckResult $IgnoreVersionCheckResult"
Write-OctopusSuccess " -SkipPausingWhenIgnoringVersionCheckResult $SkipPausingWhenIgnoringVersionCheckResult"
Write-OctopusSuccess " -CloneTenantVariables $CloneTenantVariables"
Expand Down Expand Up @@ -745,6 +751,8 @@ $cloneSpaceScript = "$PSScriptRoot\CloneSpace.ps1"
-CloneProjectRunbooks "$CloneProjectRunbooks" `
-CloneProjectVersioningReleaseCreationSettings "$CloneProjectVersioningReleaseCreationSettings" `
-CloneProjectDeploymentProcess "$CloneProjectDeploymentProcess" `
-CloneProjectLogos "$CloneProjectLogos" `
-CloneTenantLogos "$CloneTenantLogos" `
-IgnoreVersionCheckResult "$IgnoreVersionCheckResult" `
-SkipPausingWhenIgnoringVersionCheckResult "$SkipPausingWhenIgnoringVersionCheckResult" `
-CloneTenantVariables "$CloneTenantVariables" `
Expand Down
5 changes: 4 additions & 1 deletion ProjectSyncer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ param (
$CloneProjectChannelRules,
$CloneProjectVersioningReleaseCreationSettings,
$CloneProjectDeploymentProcess,
$CloneProjectLogos,
$ProcessEnvironmentScopingMatch,
$ProcessChannelScopingMatch,
$ProcessTenantTagScopingMatch,
Expand Down Expand Up @@ -55,7 +56,8 @@ $OverwriteExistingVariables = Test-OctopusOverwriteExistingVariablesParameter -p
$CloneProjectRunbooks = Test-OctopusTrueFalseParameter -parameterValue $CloneProjectRunbooks -parameterName "CloneProjectRunbooks" -defaultValue $true
$CloneProjectChannelRules = Test-OctopusTrueFalseParameter -parameterValue $CloneProjectChannelRules -parameterName "CloneProjectChannelRules" -defaultValue $false
$CloneProjectVersioningReleaseCreationSettings = Test-OctopusTrueFalseParameter -parameterValue $CloneProjectVersioningReleaseCreationSettings -parameterName "CloneProjectVersioningReleaseCreationSettings" -defaultValue $false
$CloneProjectDeploymentProcess = Test-OctopusTrueFalseParameter -parameterValue $CloneProjectDeploymentProcess -parameterName "CloneProjectDeploymentProcess" -defaultValue $false
$CloneProjectDeploymentProcess = Test-OctopusTrueFalseParameter -parameterValue $CloneProjectDeploymentProcess -parameterName "CloneProjectDeploymentProcess" -defaultValue $true
$CloneProjectLogos = Test-OctopusTrueFalseParameter -parameterValue $CloneProjectLogos -parameterName "CloneProjectLogos" -defaultValue $true

$ProcessCloningOption = Test-OctopusProcessCloningParameter -ParameterValue $ProcessCloningOption
$ProcessEnvironmentScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "ProcessEnvironmentScopingMatch" -ParameterValue $ProcessEnvironmentScopingMatch -DefaultValue "SkipUnlessPartialMatch" -SingleValueItem $false
Expand All @@ -82,6 +84,7 @@ $CloneScriptOptions = @{
CloneProjectChannelRules = $CloneProjectChannelRules;
CloneProjectVersioningReleaseCreationSettings = $CloneProjectVersioningReleaseCreationSettings;
CloneProjectDeploymentProcess = $CloneProjectDeploymentProcess;
CloneProjectLogos = $CloneProjectLogos;
ProcessEnvironmentScopingMatch = $ProcessEnvironmentScopingMatch;
ProcessChannelScopingMatch = $ProcessChannelScopingMatch;
ProcessTenantTagScopingMatch = $ProcessTenantTagScopingMatch;
Expand Down
6 changes: 5 additions & 1 deletion src/Cloners/ProjectCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ function Copy-OctopusProjects
Copy-OctopusProjectVariables -sourceChannelList $sourceChannels -destinationChannelList $destinationChannels -destinationProject $destinationProject -sourceProject $project -destinationData $DestinationData -sourceData $SourceData -cloneScriptOptions $CloneScriptOptions
Copy-OctopusProjectChannelRules -sourceChannelList $sourceChannels -destinationChannelList $destinationChannels -destinationProject $destinationProject -sourceData $SourceData -destinationData $DestinationData -cloneScriptOptions $CloneScriptOptions
$destinationProject = Copy-OctopusProjectReleaseVersioningSettings -sourceData $sourceData -sourceProject $project -sourceChannels $sourceChannels -destinationData $destinationData -destinationProject $destinationProject -destinationChannels $destinationChannels -CloneScriptOptions $CloneScriptOptions
Copy-OctopusItemLogo -sourceItem $project -destinationItem $destinationProject -sourceData $SourceData -destinationData $DestinationData -CloneScriptOptions $CloneScriptOptions

if ($CloneScriptOptions.CloneProjectLogos -eq $true)
{
Copy-OctopusItemLogo -sourceItem $project -destinationItem $destinationProject -sourceData $SourceData -destinationData $DestinationData -CloneScriptOptions $CloneScriptOptions
}
}

Write-OctopusPostCloneCleanUpHeader "*****************Ending Clone for all projects***************"
Expand Down
5 changes: 4 additions & 1 deletion src/Cloners/TenantCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ function Copy-OctopusTenants
$destinationTenant = Save-OctopusTenant -Tenant $tenantToAdd -destinationData $destinationData
$destinationData.TenantList += $destinationTenant

Copy-OctopusItemLogo -sourceItem $tenant -destinationItem $destinationTenant -sourceData $SourceData -destinationData $DestinationData -CloneScriptOptions $CloneScriptOptions
if ($CloneScriptOptions.CloneTenantLogos -eq $true)
{
Copy-OctopusItemLogo -sourceItem $tenant -destinationItem $destinationTenant -sourceData $SourceData -destinationData $DestinationData -CloneScriptOptions $CloneScriptOptions
}
}
elseif ($firstRun -eq $false)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Cloners/TenantVariableCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function Copy-OctopusTenantProjectVariables
Write-OctopusChangeLog " - No update to $($projectTemplateVariable.Label) for Environment $($destinationEnvironment.Name) because it is using the default value"
continue
}
elseif ($sourceHasValue -eq $false -and $destinationHasValue -eq $true -and $CloneScriptOptions.OverwriteExistingVariables -eq $true)
elseif ($sourceHasValue -eq $false -and $destinationHasValue -eq $true -and $CloneScriptOptions.OverwriteExistingVariables.ToString() -eq "$true")
{
Write-OctopusVerbose "The source tenant is using the default value on the source, but the destination is not and overwrite variables is true, Resetting to default value"
Write-OctopusChangeLog " - Resetting $($projectTemplateVariable.Label) for Environment $($destinationEnvironment.Name) to default"
Expand All @@ -134,7 +134,7 @@ function Copy-OctopusTenantProjectVariables

continue
}
elseif ($sourceHasValue -eq $false -and $destinationHasValue -eq $true -and $CloneScriptOptions.OverwriteExistingVariables -eq $false)
elseif ($sourceHasValue -eq $false -and $destinationHasValue -eq $true -and $CloneScriptOptions.OverwriteExistingVariables.ToString() -eq "$false")
{
Write-OctopusVerbose "The source doesn't have a value but the destination does, overwrite is set to false, so leaving as is"
Write-OctopusChangeLog " - No update to $($projectTemplateVariable.Label) for Environment $($destinationEnvironment.Name) because overwrite is set to false (would reset to default)"
Expand Down Expand Up @@ -242,15 +242,15 @@ function Copy-OctopusTenantLibraryVariables
Write-OctopusChangeLog " - No update to $($projectTemplateVariable.Label) for Environment $($destinationEnvironment.Name) because it is using the default value"
continue
}
elseif ($sourceHasValue -eq $false -and $destinationHasValue -eq $true -and $CloneScriptOptions.OverwriteExistingVariables -eq $true)
elseif ($sourceHasValue -eq $false -and $destinationHasValue -eq $true -and $CloneScriptOptions.OverwriteExistingVariables.ToString() -eq "$true")
{
Write-OctopusVerbose "The source tenant is using the default value on the source, but the destination is not and overwrite variables is true, Resetting to default value"
Write-OctopusChangeLog " - Resetting $($projectTemplateVariable.Label) for Environment $($destinationEnvironment.Name) to default"

$destinationTenantVariables.LibraryVariables.$($matchingVariableSetId).Variables.PSObject.Properties.Remove($destinationVariableTemplateId)
continue
}
elseif ($sourceHasValue -eq $false -and $destinationHasValue -eq $true -and $CloneScriptOptions.OverwriteExistingVariables -eq $false)
elseif ($sourceHasValue -eq $false -and $destinationHasValue -eq $true -and $CloneScriptOptions.OverwriteExistingVariables.ToString() -eq "$false")
{
Write-OctopusVerbose "The source doesn't have a value but the destination does, overwrite is set to false, so leaving as is"
Write-OctopusChangeLog " - No update to $($projectTemplateVariable.Label) because overwrite is set to false (would reset to default)"
Expand Down
4 changes: 2 additions & 2 deletions src/Cloners/VariableSetValuesCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function Copy-OctopusVariableSetValues
Write-OctopusPostCloneCleanUp "The variable $variableName is a sensitive variable, value set to 'Dummy Value'"
}

if ($CloneScriptOptions.OverwriteExistingVariables.ToLower().Trim() -eq "addnewwithdefaultvalue")
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"
Expand All @@ -173,7 +173,7 @@ function Copy-OctopusVariableSetValues

$DestinationVariableSetVariables.Variables += $octopusVariable
}
elseif ($variableMatchType -eq "ScopeMatch" -and $CloneScriptOptions.OverwriteExistingVariables -ne $true)
elseif ($variableMatchType -eq "ScopeMatch" -and $CloneScriptOptions.OverwriteExistingVariables.ToString() -ne "$true")
{
Write-OctopusVerbose "The variable $variableName already exists on the destination with matching scope and you elected to only copy over new items, skipping this one."
Write-OctopusChangeLog " - $variableName already exists with the following scope, skipping"
Expand Down
2 changes: 1 addition & 1 deletion src/Core/ParameterVerification.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function Test-OctopusOverwriteExistingVariablesParameter
return $false
}

if ($parameterValue -ne $true -and $parameterValue -ne $false -and $parameterValue.ToLower().Trim() -ne "addnewwithdefaultvalue")
if ($parameterValue.ToString() -ne "$true" -and $parameterValue.ToString() -ne "$false" -and $parameterValue.ToString().ToLower().Trim() -ne "addnewwithdefaultvalue")
{
Write-OctopusCritical "The parameter OverwriteExistingVariables is set to $parameterValue. Acceptable values are $true, $false or AddNewWithDefaultValue"
exit 1
Expand Down
5 changes: 3 additions & 2 deletions src/Core/Util.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,16 @@ function Add-PropertyIfMissing
$objectToTest,
$propertyName,
$propertyValue,
$overwriteIfExists)
$overwriteIfExists
)

if ((Test-OctopusObjectHasProperty -objectToTest $objectToTest -propertyName $propertyName) -eq $false)
{
$objectToTest | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue

return $true
}
elseif ($null -ne $overwriteIfExists -and $overwriteIfExists -eq $true -and ((Test-OctopusObjectHasProperty -objectToTest $objectToTest -propertyName $propertyName) -eq $false))
elseif ([string]::IsNullOrWhiteSpace($overwriteIfExists) -eq $false -and $overwriteIfExists.ToString() -eq "$true" -and ((Test-OctopusObjectHasProperty -objectToTest $objectToTest -propertyName $propertyName) -eq $false))
{
$objectToTest.$propertyName = $propertyValue

Expand Down

0 comments on commit 1bdd4dd

Please sign in to comment.