Skip to content

Commit

Permalink
New Features:
Browse files Browse the repository at this point in the history
- Support for execution containers
- Support for runbook environment scoping

Bug Fixes:

- Added prefix "Warning" for all warning messages
- Added prefix "Critical Message" for all critical messages
- Fixed issue where azure account id was not found when cloning azure web apps
- Fixed issue where azure account id was not found when cloning K8s with Azure auth
- Will create unique temporary image to help prevent "file is being used by another process."
- Will attempt to delete temporary image, if it fails it will gracefully fail and warn user
  • Loading branch information
BobJWalker committed Aug 4, 2020
1 parent e8c9a93 commit 03d1073
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 9 deletions.
20 changes: 19 additions & 1 deletion src/Cloners/ActionCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ function Copy-OctopusProcessStepAction
$action.Channels = @(Convert-SourceIdListToDestinationIdList -SourceList $SourceChannelList -DestinationList $destinationChannelList -IdList $action.Channels)

Convert-OctopusProcessActionWorkerPoolId -action $action -sourceData $sourceData -destinationData $destinationData
Convert-OctopusProcessActionExecutionContainerFeedId -action $action -sourceData $sourceData -destinationData $destinationData
Convert-OctopusProcessActionStepTemplate -action $action -sourceData $sourceData -destinationData $destinationData
Convert-OctopusProcessActionManualIntervention -action $action -sourceData $sourceData -destinationData $destinationData
Convert-OctopusProcessActionFeedId -action $action -sourceData $sourceData -destinationData $destinationData
Convert-OctopusProcessActionFeedId -action $action -sourceData $sourceData -destinationData $destinationData
Convert-OctopusProcessActionPackageList -action $action

return $action
Expand All @@ -40,6 +41,23 @@ function Convert-OctopusProcessActionWorkerPoolId
}
}

function Convert-OctopusProcessActionExecutionContainerFeedId
{
param (
$action,
$sourceData,
$destinationData
)

if ((Test-OctopusObjectHasProperty -objectToTest $action -propertyName "Container"))
{
if ($null -ne $action.Container.FeedId)
{
$action.Container.FeedId = Convert-SourceIdToDestinationId -SourceList $sourceData.FeedList -DestinationList $destinationData.FeedList -IdValue $action.Container.FeedId
}
}
}

function Convert-OctopusProcessActionStepTemplate
{
param (
Expand Down
13 changes: 12 additions & 1 deletion src/Cloners/LogoCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@ function Copy-OctopusItemLogo
{
Write-OctopusVerbose "The item $($sourceItem.Name) has a logo, downloading it to clone to the destination"

$filePath = "$PSScriptRoot\TempImage.tmp"
$imageDate = Get-Date
$dateForImage = $imageDate.ToString("yyyy_MM_dd_HH_mm_ss")
$filePath = "$PSScriptRoot\TempImage_$dateForImage.tmp"
Get-OctopusItemLogo -item $sourceItem -OctopusUrl $SourceData.OctopusUrl -ApiKey $SourceData.OctopusApiKey -filepath $filePath

Write-OctopusVerbose "The item $($sourceItem.Name) has a logo to upload, uploading to destination"
Save-OctopusItemLogo -item $destinationItem -OctopusUrl $destinationData.OctopusUrl -ApiKey $destinationData.OctopusApiKey -fileContentToUpload $filePath

Write-OctopusVerbose "The temporary image for $($sourceItem.Name) has been deleted."
try {
Remove-Item $filePath
}
catch {
Write-OctopusWarning "Unable to remove the temporary image $filePath"
}

}
else
{
Expand Down
18 changes: 17 additions & 1 deletion src/Cloners/ProjectRunbookCloner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ function Copy-OctopusProjectRunbooks

$runbookToClone.ProjectId = $destinationProject.Id
$runbookToClone.PublishedRunbookSnapshotId = $null
$runbookToClone.RunbookProcessId = $null
$runbookToClone.RunbookProcessId = $null

Convert-OctopusRunbookEnvironmentIdList -runbookToClone $runbookToClone -sourceData $sourceData -destinationData $destinationData

Write-OctopusVerbose "The runbook $($runbook.Name) for $($destinationProject.Name) doesn't exist, creating it now"
$destinationRunbook = Save-OctopusProjectRunbook -Runbook $runbookToClone -DestinationData $destinationData
Expand All @@ -43,4 +45,18 @@ function Copy-OctopusProjectRunbooks

Save-OctopusProjectRunbookProcess -RunbookProcess $destinationRunbookProcess -DestinationData $destinationData
}
}

function Convert-OctopusRunbookEnvironmentIdList
{
param (
$runbookToClone,
$sourceData,
$destinationData
)

if ((Test-OctopusObjectHasProperty -objectToTest $runbookToClone -propertyName "Environments"))
{
$runbookToClone.Environments = @(Convert-SourceIdListToDestinationIdList -SourceList $SourceData.EnvironmentList -DestinationList $DestinationData.EnvironmentList -IdList $runbookToClone.Environments)
}
}
4 changes: 2 additions & 2 deletions src/Core/Logging.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ function Write-OctopusWarning
{
param($message)

Write-Host $message -ForegroundColor Yellow
Write-Host "Warning $message" -ForegroundColor Yellow
Write-OctopusVerbose $message
}

function Write-OctopusCritical
{
param ($message)

Write-Host $message -ForegroundColor Red
Write-Host "Critical Message: $message" -ForegroundColor Red
Write-OctopusVerbose $message
}

Expand Down
11 changes: 7 additions & 4 deletions src/Core/Util.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ function Convert-SourceIdToDestinationId
)

$idValueSplit = $IdValue -split "-"
if (($idValueSplit[1] -match "^[\d\.]+$") -eq $false)
if ($idValueSplit.Length -le 2)
{
Write-OctopusVerbose "The id value $idValue is a built in id, no need to convert, returning it."
return $IdValue
if (($idValueSplit[1] -match "^[\d\.]+$") -eq $false)
{
Write-OctopusVerbose "The id value $idValue is a built in id, no need to convert, returning it."
return $IdValue
}
}

Write-OctopusVerbose "Getting Name of $IdValue"
$sourceItem = Get-OctopusItemById -ItemList $SourceList -ItemId $IdValue

Expand Down

0 comments on commit 03d1073

Please sign in to comment.