forked from OctopusDeployLabs/SpaceCloner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectSyncer.ps1
140 lines (119 loc) · 7.48 KB
/
ProjectSyncer.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
param (
$SourceOctopusUrl,
$SourceOctopusApiKey,
$SourceSpaceName,
$ParentProjectName,
$ChildProjectsToSync,
$RunbooksToClone,
$OverwriteExistingVariables,
$CloneProjectRunbooks,
$CloneProjectChannelRules,
$CloneProjectVersioningReleaseCreationSettings,
$CloneProjectDeploymentProcess,
$ProcessEnvironmentScopingMatch,
$ProcessChannelScopingMatch,
$VariableChannelScopingMatch,
$VariableEnvironmentScopingMatch,
$VariableProcessOwnerScopingMatch,
$VariableActionScopingMatch,
$VariableMachineScopingMatch,
$VariableAccountScopingMatch,
$VariableCertificateScopingMatch,
$ProcessCloningOption,
$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", "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", "ActionCloner.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Cloners", "LibraryVariableSetCloner.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Cloners", "LogoCloner.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Cloners", "ParentProjectTemplateSyncer.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Cloners", "ProcessCloner.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Cloners", "ProjectChannelCloner.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Cloners", "ProjectChannelRuleCloner.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Cloners", "ProjectCloner.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Cloners", "ProjectDeploymentProcessCloner.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Cloners", "ProjectGroupCloner.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Cloners", "ProjectRunbookCloner.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Cloners", "ProjectVariableCloner.ps1"))
. ([System.IO.Path]::Combine($PSScriptRoot, "src", "Cloners", "VariableSetValuesCloner.ps1"))
$ErrorActionPreference = "Stop"
if ($null -eq $OverwriteExistingVariables)
{
$OverwriteExistingVariables = $false
}
if ($null -eq $CloneProjectRunbooks)
{
$CloneProjectRunbooks = $true
}
if ($null -eq $CloneProjectChannelRules)
{
$CloneProjectChannelRules = $false
}
if ($null -eq $CloneProjectVersioningReleaseCreationSettings)
{
$CloneProjectVersioningReleaseCreationSettings = $false
}
if ($null -eq $CloneProjectDeploymentProcess)
{
$CloneProjectDeploymentProcess = $true
}
if ($null -eq $RunbooksToClone)
{
$RunbooksToClone = "all"
}
if ($null -eq $WhatIf)
{
$WhatIf = $false
}
if ([string]::IsNullOrWhiteSpace($ProcessCloningOption))
{
$ProcessCloningOption = "KeepAdditionalDestinationSteps"
}
elseif ($ProcessCloningOption.ToLower().Trim() -ne "keepadditionaldestinationsteps" -and $ProcessCloningOption.ToLower().Trim() -ne "sourceonly")
{
Write-OctopusCritical "The parameter ProcessCloningOption is set to $ProcessCloningOption. Acceptable values are KeepAdditionalDestinationSteps or SourceOnly."
exit 1
}
$ProcessEnvironmentScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "ProcessEnvironmentScopingMatch" -ParameterValue $ProcessEnvironmentScopingMatch -DefaultValue "SkipUnlessPartialMatch" -SingleValueItem $false
$ProcessChannelScopingMatch = Test-OctopusScopeMatchParameter -ParameterName "ProcessChannelScopingMatch" -ParameterValue $ProcessChannelScopingMatch -DefaultValue "SkipUnlessPartialMatch" -SingleValueItem $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
$CloneScriptOptions = @{
OverwriteExistingVariables = $OverwriteExistingVariables;
CloneProjectRunbooks = $CloneProjectRunbooks;
ChildProjectsToSync = $ChildProjectsToSync;
ParentProjectName = $ParentProjectName;
RunbooksToClone = $RunbooksToClone;
CloneProjectChannelRules = $CloneProjectChannelRules;
CloneProjectVersioningReleaseCreationSettings = $CloneProjectVersioningReleaseCreationSettings;
CloneProjectDeploymentProcess = $CloneProjectDeploymentProcess;
ProcessEnvironmentScopingMatch = $ProcessEnvironmentScopingMatch;
ProcessChannelScopingMatch = $ProcessChannelScopingMatch;
VariableChannelScopingMatch = $VariableChannelScopingMatch;
VariableEnvironmentScopingMatch = $VariableEnvironmentScopingMatch;
VariableProcessOwnerScopingMatch = $VariableProcessOwnerScopingMatch;
VariableActionScopingMatch = $VariableActionScopingMatch;
VariableMachineScopingMatch = $VariableMachineScopingMatch;
VariableAccountScopingMatch = $VariableAccountScopingMatch;
VariableCertificateScopingMatch = $VariableCertificateScopingMatch;
ProcessCloningOption = $ProcessCloningOption;
}
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 = $sourceData
Sync-OctopusMasterOctopusProjectWithChildProjects -sourceData $sourceData -destinationData $destinationData -CloneScriptOptions $CloneScriptOptions
$logPath = Get-OctopusLogPath
$cleanupLogPath = Get-OctopusCleanUpLogPath
Write-OctopusSuccess "The script to sync $ChildProjectsToSync from $ParentProjectName on $SourceUrl has completed. 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."