Hi @jeremy.miller
Case Explanation :
I was trying to deploy a Package-Id "ABCD" which has multiple version and i want to deploy only selective one on target.
In order to do it, i know i can go ahead to create release two times and select each individual version for Package-Id "ABCD".
Then i thought , how i can do it through automation using octo.exe and PowerShell , then i wrote the script which do it's job by creating release one by one after each previous successfully deployment.
Problem Statement :
In octopus project variable i have mentioned a variable name called Clientelist and i am passing variable values like "ABCD|EFGH|IJKL" which are the client names where each one has it's own individual database and above deplyoed scripts will run one by one.
My concern is that in PowerShell script while selecting clientname from Clientelist, sometime I am getting the client name exactly as I have put them in octopus project variable and sometimes I really get the all the clients names from the directory instead which i have mentioned in octopus project variable.
Octo.exe and powershell snippet.
#Canary ClientList
$ClientList = “ABCD”,“EFGH”,“IJKL”
#Global Variable
$Drive = “C:”
$Package = “ABCD”
$ProjectName = “Database Upgrade”
$EnvironmentType = “CLIENTSTABLE”
$PackageIDVersions = “x.x.x”, “y.y.y”
$OctopusServerURL = “OctopusURL”
$OctopusServerApiKey = “API-xxxxxxxxxxxxxxxxxx”
$PackageIDVersions = $PackageIDVersions.Split(",")
$SourceOctopusServerPath = “$Drive\Octopus\Packages\Spaces-1\feeds-builtin”
#Go To Octo.exe Location
Set-Location -Path “$Drive:\Octopus”
foreach ($PackageIDVersion in $PackageIDVersions) {
#Base Package Information
$PackageFileName = (Get-ChildItem -Path "Microsoft.PowerShell.Core\FileSystem::$SourceOctopusServerPath\$Package" -Filter "*.$PackageIDVersion.*" | Sort-Object LastAccessTime -Descending | Select-Object -First 1).Name
$PackageFileVersion = [IO.Path]::GetFileNameWithoutExtension($PackageFileName).Substring("19")
$ReleaseNotes = "Deploy Base Database Package $PackageFileName On $EnvironmentType"
#Console Print
Write-Host "$ReleaseNotes" -ForegroundColor Green
cmd.exe /c .\Octo.exe create-release --project="$ProjectName" `
--package="Deploy PGO Database:$PackageFileVersion" `
--deployto="$EnvironmentType" --releasenotes="$ReleaseNotes" `
--progress --waitfordeployment `
--server="$OctopusServerURL" --apikey "$OctopusServerApiKey" }
$ExecuteDatabaseReleaseNotes = “Upgrade $ClientList Database With Delta Script Of Base x.x.x & y.y.y”
cmd.exe /c .\Octo.exe create-release --project="$ProjectName" --deployto="$EnvironmentType" --releasenotes="$ExecuteDatabaseReleaseNotes"
–progress --waitfordeployment `
–server="$OctopusServerURL" --apikey “$OctopusServerApiKey”
Octopus Project Steps : Get The the Client List Using PowerShell
I have folder name as websites under which following are the sub directories "CLIENTSTABLEABCDPREVIEW","CLIENTSTABLEFGHPREVIEW","CLIENTSTABLEIJKLPREVIEW",CLIENTSTABLEMNOPPREVIEW.
I am using following using PowerShell snippet to get the list of client and desired output should be only three folder instead of four. Sometimes it works and sometime it does not. Just wanted to tell you that all are getting passed through prompt variables.
$EnvironmentNameList = ((Get-ChildItem -Path "Microsoft.PowerShell.Core\FileSystem::\\$AppServer1HostName\" -Exclude "XYZ" | Where-Object { ($_.Name.ToUpper().EndsWith('PREVIEW')) -and ($_.Name.ToUpper() -match "$ClientList")) }).Name
Octopus Project Steps : Database Script Execution Steps
Part-A : Example :
-
Deployed Package Version : x.x.x of Package-Id : “ABCD” on target database server under “C:\DatabaseScripts\x.x.x”.
-
Using PowerShell get the names of client folder directory names and get the database information from application file.
-
Using PowerShell “Set-Location” command go to C:\DatabaseScripts\x.x.x".
-
Execute Database.cmd against database server & database name which is input from Point #3.
Part-B : Example :
-
Deployed Package Version : y.y.y of Package-Id : “ABCD” on target database server under “C:\DatabaseScripts\y.y.y”.
-
Using PowerShell get the names of client folder directory names and get the database information from application file.
-
Using PowerShell “Set-Location” command go to C:\DatabaseScripts\y.y.y".
-
Execute Database.cmd against database server & database name which is input from Point #3.
Note : I have tried Octopus.Client.dll using REST API and it seems to me not broking now. I guess there is some issue in octo.exe while handling some tedious tasks. But still i request to you to provide your thoughts or any alternative solution of this problem.