-
Notifications
You must be signed in to change notification settings - Fork 18
/
CloneLibraryVariableSet.ps1
82 lines (68 loc) · 6.07 KB
/
CloneLibraryVariableSet.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
param (
$SourceOctopusUrl,
$SourceOctopusApiKey,
$SourceSpaceName,
$DestinationOctopusUrl,
$DestinationOctopusApiKey,
$DestinationSpaceName,
$SourceVariableSetName,
$DestinationVariableSetName,
$OverwriteExistingVariables,
$IgnoreVersionCheckResult,
$SkipPausingWhenIgnoringVersionCheckResult,
$VariableChannelScopingMatch,
$VariableEnvironmentScopingMatch,
$VariableProcessOwnerScopingMatch,
$VariableActionScopingMatch,
$VariableMachineScopingMatch,
$VariableAccountScopingMatch,
$VariableCertificateScopingMatch,
$VariableTenantTagScopingMatch,
$WhatIf
)
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Core", "Logging.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Core", "Util.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Core", "FilteredLists.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Core", "ParameterVerification.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "DataAccess", "OctopusDataAdapter.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "DataAccess", "OctopusDataFactory.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "DataAccess", "OctopusRepository.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "DataAccess", "OctopusFakeFactory.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Cloners", "LibraryVariableSetCloner.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Cloners", "VariableSetValuesCloner.ps1"))
$ErrorActionPreference = "Stop"
$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
$VariableProcessOwnerScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "VariableProcessOwnerScopingMatch" -ParameterValue $VariableProcessOwnerScopingMatch -DefaultValue "SkipUnlessPartialMatch" -SingleValueItem $false
$VariableActionScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "VariableActionScopingMatch" -ParameterValue $VariableActionScopingMatch -DefaultValue "SkipUnlessPartialMatch" -SingleValueItem $false
$VariableMachineScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "VariableMachineScopingMatch" -ParameterValue $VariableMachineScopingMatch -DefaultValue "SkipUnlessPartialMatch" -SingleValueItem $false
$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 $true
$IgnoreVersionCheckResult = Test-OctopusTrueFalseParameter -parameterValue $IgnoreVersionCheckResult -parameterName "IgnoreVersionCheckResult" -defaultValue $false
$SkipPausingWhenIgnoringVersionCheckResult = Test-OctopusTrueFalseParameter -parameterValue $SkipPausingWhenIgnoringVersionCheckResult -parameterName "SkipPausingWhenIgnoringVersionCheckResult" -defaultValue $false
$WhatIf = Test-OctopusTrueFalseParameter -parameterValue $WhatIf -parameterName "WhatIf" -defaultValue $false
$CloneScriptOptions = @{
OverwriteExistingVariables = $OverwriteExistingVariables;
LibraryVariableSetsToClone = $SourceVariableSetName;
DestinationVariableSetName = $DestinationVariableSetName;
VariableChannelScopingMatch = $VariableChannelScopingMatch;
VariableEnvironmentScopingMatch = $VariableEnvironmentScopingMatch;
VariableProcessOwnerScopingMatch = $VariableProcessOwnerScopingMatch;
VariableActionScopingMatch = $VariableActionScopingMatch;
VariableMachineScopingMatch = $VariableMachineScopingMatch;
VariableAccountScopingMatch = $VariableAccountScopingMatch;
VariableCertificateScopingMatch = $VariableCertificateScopingMatch;
VariableTenantTagScopingMatch = $VariableTenantTagScopingMatch;
}
Write-OctopusVerbose "The clone parameters sent in are:"
Write-OctopusVerbose $($CloneScriptOptions | ConvertTo-Json -Depth 10)
$sourceData = Get-OctopusData -octopusUrl $SourceOctopusUrl -octopusApiKey $SourceOctopusApiKey -spaceName $SourceSpaceName -whatIf $whatIf
$destinationData = Get-OctopusData -octopusUrl $DestinationOctopusUrl -octopusApiKey $DestinationOctopusApiKey -spaceName $DestinationSpaceName -whatIf $whatIf
Compare-OctopusVersions -SourceData $sourceData -DestinationData $destinationData -IgnoreVersionCheckResult $IgnoreVersionCheckResult -SkipPausingWhenIgnoringVersionCheckResult $SkipPausingWhenIgnoringVersionCheckResult
Copy-OctopusLibraryVariableSets -SourceData $sourceData -DestinationData $destinationData -cloneScriptOptions $CloneScriptOptions
$logPath = Get-OctopusLogPath
$cleanupLogPath = Get-OctopusCleanUpLogPath
Write-OctopusSuccess "The script to clone the variable set $SourceVariableSetName on the space $SourceSpaceName on $SourceOctopusUrl to the variable set $DestinationVariableSetName on the space $DestinationSpaceName on $DestinationOctopusUrl. Please see $logPath for more details."
Write-OctopusWarning "You might have post clean-up tasks to finish. Any sensitive variables or encrypted values were created with dummy values which you must replace. Please see $cleanUpLogPath for a list of items to fix."