Skip to content

Instantly share code, notes, and snippets.

@meehanman
Created May 14, 2019 14:10
Show Gist options
  • Save meehanman/da1aaec0509d657fc6e03d88d931ee1c to your computer and use it in GitHub Desktop.
Save meehanman/da1aaec0509d657fc6e03d88d931ee1c to your computer and use it in GitHub Desktop.
DevOps | Automated upgrade for old configuration to new format. For upgrading the project's, see: https://gist.github.com/meehanman/7947b9076845c6c2dd606eb258bfbcec
function Transform-Config {
Param ([string]$application)
$SaveFolderLoc = "%system.teamcity.build.workingDir%\Configuration"
$folders = Get-ChildItem -Path "%system.teamcity.build.workingDir%\Dev4.0\Configuration\*" | ?{ $_.PSIsContainer }
New-Item -Path $SaveFolderLoc -Name "$($application)" -ItemType "directory"
foreach ($folder in $folders)
{
$configs = Get-ChildItem -Path "%system.teamcity.build.workingDir%\Dev4.0\Configuration\$($folder.Name)\$($application)" -Recurse -Force
foreach($configFile in $configs)
{
#Write-Output "$($configFile.FullName) $($folder.name)"
#Advice.Web.Config
$currentFile = $($configFile.FullName)
#[Advice, Web, Config]
$currentFileSplit = $($configFile.Name).Split(".")
#Advice.Web
$currentFileName = "$($($currentFileSplit)[0..($($currentFileSplit).Count-2)] -join ".")"
#Config
$currentFileExt = "$($currentFileSplit[$($currentFileSplit).Length-1])"
#DevOnline
$environment = "$($folder.name)"
$newFileLocation = "$($SaveFolderLoc)\$($application)\$($currentFileName).$($environment).$($currentFileExt)"
Copy-Item $currentFile $newFileLocation -Recurse -Force
}
}
}
#Create an Empty List
$applications = @()
#Get all the folders(applications) from Configuration subfolders
$folders = Get-ChildItem -Path "%system.teamcity.build.workingDir%\Dev4.0\Configuration\*\*" | ?{ $_.PSIsContainer }
#Add each foldername to the applications array and ensure there are no duplicates
foreach ($application in $folders)
{
$applications += $application.name
}
$applications = $applications | sort -unique
#Process
foreach ($application in $applications)
{
Transform-Config -application $application
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment