Skip to content

Commit

Permalink
First Check-in with default variable values
Browse files Browse the repository at this point in the history
  • Loading branch information
BobJWalker committed Nov 12, 2021
1 parent 69df1e1 commit c47e5d2
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 53 deletions.
2 changes: 1 addition & 1 deletion CloneLibraryVariableSet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ param (

$ErrorActionPreference = "Stop"

$OverwriteExistingVariables = Test-OctopusTrueFalseParameter -parameterValue $OverwriteExistingVariables -parameterName "OverwriteExistingVariables" -defaultValue $false
$OverwriteExistingVariables = Test-OctopusOverwriteExistingVariablesParameter -parameterValue $OverwriteExistingVariables -parameterName "OverwriteExistingVariables" -defaultValue $false

$VariableChannelScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "VariableChannelScopingMatch" -ParameterValue $VariableChannelScopingMatch -DefaultValue "SkipUnlessPartialMatch" -SingleValueItem $false
$VariableEnvironmentScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "VariableEnvironmentScopingMatch" -ParameterValue $VariableEnvironmentScopingMatch -DefaultValue "SkipUnlessPartialMatch" -SingleValueItem $false
Expand Down
14 changes: 7 additions & 7 deletions CloneSpace.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ param (
$PackagesToClone,
$RunbooksToClone,
$CertificatesToClone,
$OverwriteExistingVariables,
$ChannelsToClone,
$OverwriteExistingVariables,
$OverwriteExistingCustomStepTemplates,
$OverwriteExistingLifecyclesPhases,
$CloneProjectRunbooks,
Expand All @@ -48,7 +49,7 @@ param (
$VariableCertificateScopingMatch,
$InfrastructureEnvironmentScopingMatch,
$InfrastructureTenantScopingMatch,
$ProcessCloningOption,
$ProcessCloningOption,
$WhatIf
)

Expand Down Expand Up @@ -93,7 +94,7 @@ param (

$ErrorActionPreference = "Stop"

$OverwriteExistingVariables = Test-OctopusTrueFalseParameter -parameterValue $OverwriteExistingVariables -parameterName "OverwriteExistingVariables" -defaultValue $false
$OverwriteExistingVariables = Test-OctopusOverwriteExistingVariablesParameter -parameterValue $OverwriteExistingVariables -parameterName "OverwriteExistingVariables" -defaultValue $false
$OverwriteExistingCustomStepTemplates = Test-OctopusTrueFalseParameter -parameterValue $OverwriteExistingCustomStepTemplates -parameterName "OverwriteExistingCustomStepTemplates" -defaultValue $false
$OverwriteExistingLifecyclesPhases = Test-OctopusOverwriteExistingLifecyclesPhasesParameter -parameterValue $OverwriteExistingLifecyclesPhases

Expand All @@ -104,10 +105,8 @@ $CloneProjectVersioningReleaseCreationSettings = Test-OctopusTrueFalseParameter
$CloneProjectDeploymentProcess = Test-OctopusTrueFalseParameter -parameterValue $CloneProjectDeploymentProcess -parameterName "CloneProjectDeploymentProcess" -defaultValue $false
$CloneTenantVariables = Test-OctopusTrueFalseParameter -parameterValue $CloneTenantVariables -parameterName "CloneTenantVariables" -defaultValue $false

if ($null -eq $RunbooksToClone)
{
$RunbooksToClone = "all"
}
$RunbooksToClone = Test-OctopusNewListParameter -parameterValue $RunbooksToClone -parameterName "RunbooksToClone"
$ChannelsToClone = Test-OctopusNewListParameter -parameterValue $ChannelsToClone -parameterName "ChannelsToClone"

if ($null -ne $CertificatesToClone -and $CertificatesToClone.ToLower().Trim() -eq "all")
{
Expand Down Expand Up @@ -160,6 +159,7 @@ $CloneScriptOptions = @{
SpaceTeamsToClone = $SpaceTeamsToClone;
PackagesToClone = $PackagesToClone;
RunbooksToClone = $RunbooksToClone;
ChannelsToClone = $ChannelsToClone;
CloneTeamUserRoleScoping = $CloneTeamUserRoleScoping;
CloneProjectChannelRules = $CloneProjectChannelRules;
CloneProjectVersioningReleaseCreationSettings = $CloneProjectVersioningReleaseCreationSettings;
Expand Down
98 changes: 77 additions & 21 deletions CloneSpaceProject.ps1

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ProjectSyncer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ param (

$ErrorActionPreference = "Stop"

$OverwriteExistingVariables = Test-OctopusTrueFalseParameter -parameterValue $OverwriteExistingVariables -parameterName "OverwriteExistingVariables" -defaultValue $false
$OverwriteExistingVariables = Test-OctopusOverwriteExistingVariablesParameter -parameterValue $OverwriteExistingVariables -parameterName "OverwriteExistingVariables" -defaultValue $false
$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
Expand Down
12 changes: 10 additions & 2 deletions src/Cloners/ProjectChannelCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ function Copy-OctopusProjectChannels
Write-OctopusChangeLog " - Channels"
$projectChannels = @()

foreach($channel in $sourceChannelList)
$filteredList = Get-OctopusFilteredList -itemList $sourceChannelList -itemType "Project Channels" -filters $cloneScriptOptions.ChannelsToClone

if ($filteredList.length -eq 0)
{
Write-OctopusChangeLog " - No channels found to clone matching the filters"
return
}

foreach($channel in $filteredList)
{
$matchingChannel = Get-OctopusItemByName -ItemList $destinationChannelList -ItemName $channel.Name

Expand All @@ -27,7 +35,7 @@ function Copy-OctopusProjectChannels
}

$cloneChannel.Rules = @()
Write-OctopusVerbose "The channel $($channel.Name) does not exist for the project $($destinationProject.Name), creating one now. Please note, I cannot create version rules, so those will be emptied out"
Write-OctopusVerbose "The channel $($channel.Name) does not exist for the project $($destinationProject.Name), creating one now. Please note, I cannot create version rules at this time, so those will be emptied out for now."
Write-OctopusChangeLog " - Add $($channel.Name)"
$newChannel = Save-OctopusProjectChannel -projectChannel $cloneChannel -destinationData $destinationData

Expand Down
2 changes: 1 addition & 1 deletion src/Cloners/TeamCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Copy-OctopusSpaceTeams
{
if ($null -eq $team.SpaceId)
{
Write-OctopusVerbose "The team $($team.Name) is a space team, skipping"
Write-OctopusVerbose "The team $($team.Name) is a system team, skipping"
continue
}

Expand Down
21 changes: 14 additions & 7 deletions src/Cloners/VariableSetValuesCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,26 @@ function Copy-OctopusVariableSetValues
if ($variableMatchType -eq "NoMatch")
{
Write-OctopusVerbose "New variable $variableName with unique scoping has been found. Adding to list."

Write-OctopusChangeLog " - Add $variableName with value $($octopusVariable.Value)"
Write-OctopusVariableScopeToChangeLog -octopusVariable $octopusVariable -destinationVariableSetVariables $destinationVariableSetVariables


if ($octopusVariable.Value -eq "Dummy Value")
{
Write-OctopusPostCloneCleanUp "The variable $variableName is a sensitive variable, value set to 'Dummy Value'"
}

if ($CloneScriptOptions.OverwriteExistingVariables.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"
}

Write-OctopusChangeLog " - Add $variableName with value $($octopusVariable.Value)"
Write-OctopusVariableScopeToChangeLog -octopusVariable $octopusVariable -destinationVariableSetVariables $destinationVariableSetVariables

$octopusVariable.Id = $null

$DestinationVariableSetVariables.Variables += $octopusVariable
}
elseif ($variableMatchType -eq "ScopeMatch" -and $CloneScriptOptions.OverwriteExistingVariables -eq $false)
elseif ($variableMatchType -eq "ScopeMatch" -and $CloneScriptOptions.OverwriteExistingVariables -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 Expand Up @@ -219,8 +225,9 @@ function Compare-OctopusVariables
{
Write-OctopusVerbose " The source variable name $($sourceVariable.Name) and the destination $($destinationVariable.Name) have the same sensitivity. Moving on to checking scoping."
}

if ($destinationVariable.IsSensitive -eq $false -and $sourceVariable.IsSensitive -eq $false -and $sourceVariable.Value.ToLower().Trim() -eq $destinationVariable.Value.ToLower().Trim())

Write-OctopusVerbose "Comparing $($sourceVariable.Value) with $($destinationVariable.Value)"
if ($destinationVariable.IsSensitive -eq $false -and $sourceVariable.IsSensitive -eq $false -and [string]::IsNullOrWhiteSpace($sourceVariable.Value) -eq $false -and [string]::IsNullOrWhiteSpace($destinationVariable.Value) -eq $false -and $sourceVariable.Value.ToLower().Trim() -eq $destinationVariable.Value.ToLower().Trim())
{
Write-OctopusVerbose " The source variable and the destination variable have the same name AND the same value"
return "ValueMatch"
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.0.0"
$clonerVersion = "3.1.0"

$logFolder = "$PSScriptRoot\..\..\"
$logArchiveFolder = "$PSScriptRoot\..\..\logs\archive_$currentDateFormatted"
Expand Down
140 changes: 128 additions & 12 deletions src/Core/Util.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,67 @@ function Get-OctopusExclusionList
param(
$itemList,
$itemType,
$filters
)
$filters,
$includeFilters
)

if ([string]::IsNullOrWhiteSpace($includeFilters))
{
$filteredList = New-OctopusFilteredList -itemList $itemList -itemType $itemType -filters $filters

$filteredList = New-OctopusFilteredList -itemList $itemList -itemType $itemType -filters $filters

if ($filteredList.Length -eq 0)
if ($filteredList.Length -eq 0)
{
Write-OctopusVerbose "No $itemType items were found to exclude"
}

return $filteredList
}

$filteredList = @()

if ($includeFilters.ToLower().Trim() -eq "all")
{
Write-OctopusWarning "No $itemType items were found to exclude"
}
Write-OctopusVerbose "The include filter was set to all for $itemType, there are no items to exclude."

return $filteredList
}

if ($null -eq $itemList)
{
Write-OctopusVerbose "There were no items in the item list $itemType, nothing to exclude."

return $filteredList
}

Write-OctopusVerbose "The inclusion filter $includeFilters for $itemType was sent in. Going to build the exclusion list based on that."
$splitFilters = $includeFilters -split ","

foreach ($item in $itemList)
{
$matchFound = $false
foreach ($filter in $splitFilters)
{
Write-OctopusVerbose "Checking to see if filter $filter matches $($item.Name)"
if ([string]::IsNullOrWhiteSpace($filter))
{
Write-OctopusVerbose "The filter $filter was null or empty, that's odd, moving onto the next filter"
continue
}

if ($item.Name -like $filter)
{
Write-OctopusVerbose "The filter $filter matches $($item.Name), it will not be included in the exclusion list."
$matchFound = $true
}
}

if ($matchFound -eq $false)
{
Write-OctopusVerbose "No match was found for $($item.Name), adding it to the exclusion list."
$filteredList += $item
}
}

return $filteredList
}

Expand All @@ -389,6 +440,11 @@ function New-OctopusFilteredList

if ([string]::IsNullOrWhiteSpace($filters) -eq $false -and $null -ne $itemList)
{
if ([string]::IsNullOrWhiteSpace($filters) -eq $false -and $filters.ToLower().Trim() -eq "all")
{
return $itemList
}

$splitFilters = $filters -split ","

foreach($item in $itemList)
Expand All @@ -400,11 +456,6 @@ function New-OctopusFilteredList
{
continue
}
if (($filter).ToLower().Trim() -eq "all")
{
Write-OctopusVerbose "The filter is 'all' -> adding $($item.Name) to $itemType filtered list"
$filteredList += $item
}
elseif ($item.Name -like $filter)
{
Write-OctopusVerbose "The filter $filter matches $($item.Name), adding $($item.Name) to $itemType filtered list"
Expand Down Expand Up @@ -754,4 +805,69 @@ function Test-OctopusOverwriteExistingLifecyclesPhasesParameter

Write-OctopusVerbose "The value sent in for OverwriteExistingLifecyclesPhases is $parameterValue."
return $parameterValue
}

function Test-OctopusOverwriteExistingVariablesParameter
{
param (
$parameterValue
)

if ([string]::IsNullOrWhiteSpace($parameterValue))
{
Write-OctopusVerbose "The parameter OverwriteExistingVariables was empty or null, setting to $false."
return $false
}

if ($parameterValue -ne $true -and $parameterValue -ne $false -and $parameterValue.ToLower().Trim() -ne "addnewwithdefaultvalue")
{
Write-OctopusCritical "The parameter OverwriteExistingVariables is set to $parameterValue. Acceptable values are $true, $false or AddNewWithDefaultValue"
exit 1
}

Write-OctopusVerbose "The value sent in for OverwriteExistingVariables is $parameterValue."

return $parameterValue
}

function Test-OctopusNewListParameter
{
param (
$parameterValue,
$parameterName
)

if ([string]::IsNullOrWhiteSpace($parameterValue))
{
Write-OctopusWarning "The paramter $parameterName is empty or null but this is a paramter you previously didn't have to set. Setting to 'all' so it doesn't break your existing clone."
return "all"
}

Write-Verbose "The value sent in for $parameterName was $parameterValue"

return $parameterValue
}

function Test-OctopusIncludeExcludeFilterParameter
{
param (
$includeFilters,
$excludeFilters,
$parameterName
)

if ([string]::IsNullOrWhiteSpace($includeFilters) -eq $false -and [string]::IsNullOrWhiteSpace($excludeFilters) -eq $false)
{
Write-OctopusCritical "Both include and exclude filters were set for $parameterName. That is not allowed, either pick an exclude filter or an include filter. Exiting."
exit 1
}

if ([string]::IsNullOrWhiteSpace($includeFilters) -and [string]::IsNullOrWhiteSpace($excludeFilters))
{
Write-OctopusVerbose "Both include and exclude filters were empty for $parameterName. This means you want to include everything. Setting the include filter to all."
return "all"
}

Write-OctopusVerbose "The values for $parameterName are include filters: $includeFilters and exclude filters: $excludeFilters"
return $includeFilters
}

0 comments on commit c47e5d2

Please sign in to comment.