Check for other running project deployments

Hi

For anyone who is interested, I have written a script that will check for other running deployments so you can pause another deployment execution if another project deployment is running. You need to download octo.exe and set up a user and API key to use it but thought it may be useful.

function CheckForRunningProjects{
param(
[Parameter(Mandatory=$True)] $currentproj = “”
)
Set-Alias Octo “C:\Octopus\OctopPack\Octo.exe”

$inproject = $false
$result = “”

$EXECUTING = $true
Write-Host “Checking for running projects other than $currentproj”
Do{
$result = “”
$var = octo list-latestdeployments --server=http://youroctopusURL/ --apiKey=API-YOURAPIKEY
foreach($line in $var) {

    if($line -match "Project"){
        $proj = $line.Replace("- Project: ","")
        $inproject = $true
    }
    if($inproject -and $line -match "State" -and $line -match "Executing" -and $proj -notmatch $currentproj)
    {
        $result = "$proj is in progress, please wait..."
        Write-Host $result
        $EXECUTING = $true
    }
    if($line -eq "")
    {
        $proj = ""
        $inproject = $false
    }
    if($result -eq "")
    {
        $EXECUTING = $false
    }
    else
    {
        $EXECUTING = $true
    }       


}

IF($EXECUTING)
{    
start-sleep -Seconds 5
}

} while($EXECUTING)

Write-Host “No Other Projects Running”

}

Hi Tom_Wyatt,

Thank you for sharing this. I understand what you’re trying to do here.I however feel that using the Octo.exe is less efficient then using the API itself. This will obviously not require you to download anything.

I have a central project that deploys multiple other releases from other projects and I want to wait until a release has finished before kicking off the next.

If I’m not mistaken. Octopus has solved this with the “Deploy a release” step.

Thanks,
Lance

He doesn’t state he wants to do any chaining of deployments. He is trying to pause deployments to ensure another deployment is finished so there are no conflicts between individually kicked off deplyoments.