Skip to content

Commit

Permalink
Fixes #32 and #33. Also, adding a CloneStepTemplateLogo option.
Browse files Browse the repository at this point in the history
  • Loading branch information
BobJWalker committed Nov 22, 2021
1 parent 29b8754 commit 37efcbb
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 34 deletions.
3 changes: 3 additions & 0 deletions CloneSpace.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ param (
$CloneProjectDeploymentProcess,
$CloneProjectLogos,
$CloneTenantLogos,
$CloneStepTemplateLogos,
$CloneTenantVariables,
$ProcessEnvironmentScopingMatch,
$ProcessChannelScopingMatch,
Expand Down Expand Up @@ -115,6 +116,7 @@ $CloneProjectVersioningReleaseCreationSettings = Test-OctopusTrueFalseParameter
$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
$CloneStepTemplateLogos = Test-OctopusTrueFalseParameter -parameterValue $CloneStepTemplateLogos -parameterName "CloneStepTemplateLogos" -defaultValue $true
$CloneTenantVariables = Test-OctopusTrueFalseParameter -parameterValue $CloneTenantVariables -parameterName "CloneTenantVariables" -defaultValue $false

if ($null -ne $CertificatesToClone -and $CertificatesToClone.ToLower().Trim() -eq "all")
Expand Down Expand Up @@ -179,6 +181,7 @@ $CloneScriptOptions = @{
CloneProjectDeploymentProcess = $CloneProjectDeploymentProcess;
CloneTenantVariables = $CloneTenantVariables;
CloneTenantLogos = $CloneTenantLogos;
CloneStepTemplateLogos = $CloneStepTemplateLogos;
CloneProjectLogos = $CloneProjectLogos;
ProcessEnvironmentScopingMatch = $ProcessEnvironmentScopingMatch;
ProcessChannelScopingMatch = $ProcessChannelScopingMatch;
Expand Down
6 changes: 5 additions & 1 deletion CloneSpaceProject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ param (
$CloneProjectLogos,
$CloneTenantLogos,
$CloneTenantVariables,
$CloneStepTemplateLogos,
$ClonePackages,
$ProcessEnvironmentScopingMatch,
$ProcessChannelScopingMatch,
Expand Down Expand Up @@ -75,6 +76,7 @@ $CloneProjectVersioningReleaseCreationSettings = Test-OctopusTrueFalseParameter
$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
$CloneStepTemplateLogos = Test-OctopusTrueFalseParameter -parameterValue $CloneStepTemplateLogos -parameterName "CloneStepTemplateLogos" -defaultValue $true
$CloneTenantVariables = Test-OctopusTrueFalseParameter -parameterValue $CloneTenantVariables -parameterName "CloneTenantVariables" -defaultValue $false
$ClonePackages = Test-OctopusTrueFalseParameter -parameterValue $ClonePackages -parameterName "ClonePackages" -defaultValue $false

Expand All @@ -90,7 +92,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
$VariableWorkerPoolScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "VariableWorkerPoolScopingMatch" -ParameterValue $VariableWorkerPoolScopingMatch -DefaultValue "SkipUnlessExactMatch" -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 @@ -710,6 +712,7 @@ Write-OctopusSuccess " -CloneProjectVersioningReleaseCreationSettings $ClonePro
Write-OctopusSuccess " -CloneProjectDeploymentProcess $CloneProjectDeploymentProcess"
Write-OctopusSuccess " -CloneProjectLogos $CloneProjectLogos"
Write-OctopusSuccess " -CloneTenantLogos $CloneTenantLogos"
Write-OctopusSuccess " -CloneStepTemplateLogos $CloneStepTemplateLogos"
Write-OctopusSuccess " -IgnoreVersionCheckResult $IgnoreVersionCheckResult"
Write-OctopusSuccess " -SkipPausingWhenIgnoringVersionCheckResult $SkipPausingWhenIgnoringVersionCheckResult"
Write-OctopusSuccess " -CloneTenantVariables $CloneTenantVariables"
Expand Down Expand Up @@ -766,6 +769,7 @@ $cloneSpaceScript = "$PSScriptRoot\CloneSpace.ps1"
-CloneProjectDeploymentProcess "$CloneProjectDeploymentProcess" `
-CloneProjectLogos "$CloneProjectLogos" `
-CloneTenantLogos "$CloneTenantLogos" `
-CloneStepTemplateLogos "$CloneStepTemplateLogos" `
-IgnoreVersionCheckResult "$IgnoreVersionCheckResult" `
-SkipPausingWhenIgnoringVersionCheckResult "$SkipPausingWhenIgnoringVersionCheckResult" `
-CloneTenantVariables "$CloneTenantVariables" `
Expand Down
1 change: 1 addition & 0 deletions docs/CloneSpaceParameterReference.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ The values for these options are either `True`, `False` or `null`. Null will ca
- `CloneProjectVersioningReleaseCreationSettings`: Indicates if the release versioning strategy and release creation strategy should be cloned. The default is `false`.
- `CloneProjectLogos`: Indicates if the project logo should be cloned. The default is `true`. Recommended setting to `true` on the initial clone, `false` on subsequent clones to keep the cloning fast.
- `CloneTenantLogos`: Indicates if the tenant logo should be cloned. The default is `true`. Recommended setting to `true` on the initial clone, `false` on subsequent clones to keep the cloning fast.
- `CloneStepTemplateLogos`: Indicates if the step template logo should be cloned. The default is `true`. Recommended setting to `true` on the initial clone, `false` on subsequent clones to keep the cloning fast.
- `CloneTeamUserRoleScoping`: Indicates if the space teams should have their scoping cloned. Will use the same teams based on parameter `SpaceTeamsToClone`. The default is`false`.
- `CloneTenantVariables`: Indicates if tenant variables should be cloned. The default is`false`.
- `IgnoreVersionCheckResult`: Indicates if the script should ignore version checks rules and proceed with the clone. This should only be used for cloning to test instances of Octopus Deploy. The default is `false`.
Expand Down
1 change: 1 addition & 0 deletions docs/CloneSpaceProjectParameterReference.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ The values for these options are either `True`, `False` or `null`. Null will ca
- `CloneProjectVersioningReleaseCreationSettings`: Indicates if the same versioning rules will be applied to the project. The default is `false`.
- `CloneProjectLogos`: Indicates if the project logo should be cloned. The default is `true`. Recommended setting to `true` on the initial clone, `false` on subsequent clones to keep the cloning fast.
- `CloneTenantLogos`: Indicates if the tenant logo should be cloned. The default is `true`. Recommended setting to `true` on the initial clone, `false` on subsequent clones to keep the cloning fast.
- `CloneStepTemplateLogos`: Indicates if the step template logo should be cloned. The default is `true`. Recommended setting to `true` on the initial clone, `false` on subsequent clones to keep the cloning fast.
- `ClonePackages`: Indicates if any packages should be cloned. Set this to `false` to skip cloning packages. The defualt is `true`.
- `CloneTeamUserRoleScoping`: Indicates if the space teams should have their scoping cloned. Will use the same teams based on parameter `SpaceTeamsToClone`. The default is`false`.
- `CloneTenantVariables`: Indicates if tenant variables should be cloned. The default is`false`.
Expand Down
7 changes: 5 additions & 2 deletions src/Cloners/StepTemplateCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ function Copy-OctopusStepTemplates

$destinationStepTemplate = Save-OctopusStepTemplate -StepTemplate $stepTemplateToClone -DestinationData $destinationData

Copy-OctopusItemLogo -sourceItem $stepTemplate -destinationItem $destinationStepTemplate -sourceData $SourceData -destinationData $DestinationData -CloneScriptOptions $CloneScriptOptions

if ($cloneScriptOptions.CloneStepTemplateLogos -eq $true)
{
Copy-OctopusItemLogo -sourceItem $stepTemplate -destinationItem $destinationStepTemplate -sourceData $SourceData -destinationData $DestinationData -CloneScriptOptions $CloneScriptOptions
}

$destinationData.StepTemplates = Update-OctopusList -itemList $destinationData.StepTemplates -itemToReplace $destinationStepTemplate
}
else
Expand Down
62 changes: 37 additions & 25 deletions src/Core/FilteredLists.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -123,40 +123,52 @@ function New-OctopusFilteredList

Write-OctopusSuccess "Creating filter list for $itemType with a filter of $filters"

if ([string]::IsNullOrWhiteSpace($filters) -eq $false -and $null -ne $itemList)
if ([string]::IsNullOrWhiteSpace($filters) -eq $true)
{
Write-OctopusWarning "The filter for $itemType was not set. Returning empty list."
return $filteredList
}

if ($null -eq $itemList -or $itemList.Count -eq 0)
{
Write-OctopusWarning "The item list for $itemType was empty. Returning an empty list."
return $filteredList
}

if ([string]::IsNullOrWhiteSpace($filters) -eq $false -and $filters.ToLower().Trim() -eq "all")
{
if ([string]::IsNullOrWhiteSpace($filters) -eq $false -and $filters.ToLower().Trim() -eq "all")
Write-OctopusVerbose "The filter was set to 'all' returning the entire list of $itemType."
return $itemList
}

$splitFilters = $filters -split ","

foreach ($filter in $splitFilters)
{
if ([string]::IsNullOrWhiteSpace($filter))
{
return $itemList
}
Write-OctopusVerbose "The filter is an empty string, moving onto the next item."
continue
}

$splitFilters = $filters -split ","
$filterToCompare = $filter.ToLower().Trim()

foreach($item in $itemList)
{
foreach ($filter in $splitFilters)
{
Write-OctopusVerbose "Checking to see if $filterToCompare matches $($item.Name)"

if ($item.Name.ToLower().Trim() -like $filterToCompare)
{
Write-OctopusVerbose "Checking to see if $filter matches $($item.Name)"
if ([string]::IsNullOrWhiteSpace($filter))
{
continue
}
elseif ($item.Name -like $filter)
{
Write-OctopusVerbose "The filter $filter matches $($item.Name), adding $($item.Name) to $itemType filtered list"
$filteredList += $item
}
else
{
Write-OctopusVerbose "The item $($item.Name) does not match filter $filter"
}
Write-OctopusVerbose "The filter $filter matches $($item.Name), adding $($item.Name) to $itemType filtered list"
$filteredList += $item
}
else
{
Write-OctopusVerbose "The item $($item.Name) does not match filter $filter. Moving onto next item."
continue
}
}
}
else
{
Write-OctopusWarning "The filter for $itemType was not set."
}

return $filteredList
}
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.2"
$clonerVersion = "3.2.3"

$logFolder = "$PSScriptRoot\..\..\"
$logArchiveFolder = "$PSScriptRoot\..\..\logs\archive_$currentDateFormatted"
Expand Down
13 changes: 8 additions & 5 deletions src/DataAccess/OctopusDataAdapter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ function Invoke-OctopusApi
}
catch
{
Write-OctopusCritical "There was an error making a $method call to $url. All request information (JSON body specifically) is stored in the log. Please check that for more information."

if ($null -ne $_.Exception.Response)
{
if ($_.Exception.Response.StatusCode -eq 401)
Expand All @@ -90,20 +92,21 @@ function Invoke-OctopusApi
}
elseif ($_.ErrorDetails.Message)
{
Write-OctopusVerbose -Message "Error calling $url StatusCode: $($_.Exception.Response) $($_.ErrorDetails.Message)"
Write-OctopusVerbose $_.Exception
Write-OctopusCritical -Message "Error calling $url StatusCode: $($_.Exception.Response) $($_.ErrorDetails.Message)"
Write-OctopusCritical $_.Exception
}
else
{
Write-OctopusVerbose $_.Exception
Write-OctopusCritical $_.Exception
}
}
else
{
Write-OctopusVerbose $_.Exception
Write-OctopusCritical $_.Exception
}

Throw "There was an error calling the Octopus API please check the log for more details"
Write-OctopusCritical "Exiting the SpaceCloner."
Exit 1
}
}

Expand Down

0 comments on commit 37efcbb

Please sign in to comment.