Multiple Transforms for one config

I have 2 steps that deploy files.

The first deploys the web.config and applies transforms as usual.

The second step also needs to transform the web.config that was just deployed by step 1. It has a transform file but does not have the web.config because that is in the first project.

How should i setup the project or steps to do the normal transformations so that the first and second steps transform the one web.config.

Project 1 contains:
Web.config
Web.config.Project1.transform

Project 2 contains:
Web.config.Project2.transform

Result should contain:
Web.config (this has been transformed by both Web.config.Project1.transform and Web.config.Project2.transform)

Hi Ben,

Thanks for getting in touch,

It’s definitely possible to manage this within Octopus, I’ve included a working scenario below that I made on my own system;

In this scenario, I have two packages;

ExampleTransformation.nupkg > Containing (web.config & webtwo.config)
&
ExampleTransformation2.nupkg > Containing (webthree.config)

In order for this to work, you’ll need the deploy package step containing webthree.config to action first, (or in your example web.config.Project2.transform), this is because you will need to specify an absolute path in your Configuration Transforms area of the second step.

I’ve included screenshots below to highlight this;

The end result of this is that the web.config is transformed by webtwo.config and then web.config is subsequently transformed by webthree.config

I hope this helps!

If I’ve misunderstood in any way or you require additional assistance, please let me know :slight_smile:

Have a great day!

Kind Regards,

Reece

Hey Reece,
Wow, like magic! Thanks so much for that. That works.
That takes care of it.

However, I would like to try to do it without explicitly specifying each config files source and destination because I didn’t tell you that I have a bunch of configs and specifying all of them seems error prone.

I have read and re read https://octopus.com/docs/deployment-process/configuration-files/advanced-configuration-transforms-examples.
i have a bunch of sources for the transformations and would have to specify a whole bunch of those.
Here are a couple of things I am thinking about to get the wildcard thing to happen.

  1. Bring the web.config back into the source directory after the package is unzipped and before the transform happens in the source directory, then allow the transform to take place and then have it copied back as if it were part of the package being delivered?
  2. Or Have a post process run after all the transform files have been copied over to the destination and transform that directory. (No existing packages do what octopus does which is to allow wildcards with a base directory)
  3. Or Have all the package steps unzip into the same directory and then transform and then copy to the destination after the transform has happened even though it would do it multiple times, ie once for each package.

Thanks
Ben

Hi Ben,

Thanks for getting back to me,

I greatly appreciate your detailed breakdown and patience,

Based on the information provided in your query, I’ve linked below the advanced configuration example for using an absolute path wildcard transform for multiple targets (I’m conscious you mentioned you looked at this in your earlier post, however)

Out of your three suggestions, the third option looks to be the least complex (without packaging things differently to avoid specifying each source) you can specify a CustomInstallationDirectory via the Deploy Package Step - Features to have the Transformed files copy across to the destination folder after the transform has happened, though this would occur for each package.

If I’ve misunderstood in any way, or you require further assistance please let me know :slight_smile:

Have a great day!

Kind Regards,

Reece

Hey Reece,

I ended up doing the first option.

I include the following script on each deploy files step and it works perfectly. Now I get the benefit of the normal wildcards and multiple transforms for the same file from different packages.

Thanks for the help

<#
.SYNOPSIS
copies the transform targets to the local deployment source folder.
#>

function TestPath([string]$testPath)
{
$FileExists = Test-Path $testPath
If ($FileExists -eq $True)
{
Return $true
}
Else
{
Return $false
}
}

$SourceFolderPath = Get-Location
Write-Host “SourceFolderPath: $SourceFolderPath”
$DestinationFolderPath = $OctopusParameters[“FileSystem.RootFolder”]
Write-Host “DestinationFolderPath: $DestinationFolderPath”
$FileExtension = “.transform”
Write-Host “FileExtension: $FileExtension”

$Result = (TestPath($DestinationFolderPath));
If ($Result)
{
$Result = (TestPath($SourceFolderPath));

If ($Result)
{
    $Dir = get-childitem $SourceFolderPath -recurse
    $List = $Dir | where {$_.extension -eq $FileExtension}
    $List | Foreach-Object `
    {
        $fileName, $fileExtension, $fileSegments = $_.Name.Split(".")
        $destDir = Split-Path ($_.FullName -Replace [regex]::Escape((Get-Item $SourceFolderPath).FullName), (Get-Item $DestinationFolderPath).FullName)
        Copy-Item "$destDir\$fileName.$fileExtension" -Destination $_.Directory
    }
}
else
{
    "Source Folder path is incorrect."
}

}
else
{
“Destination Folder path is incorrect.”
}

Hi Ben,

Thanks for getting back to me,

I’m glad to hear you were able to find a solution to this, I greatly appreciate your time in letting me the outcome.

If you require any further assistance in the future, please don’t hesitate to reach out! :slight_smile:

Have a great day!

Kind Regards,

Reece

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.