How do I block a release using the Octopus.Client.dll in C#? I have been looking at the API, and I am not seeing it.
I am using Octopus.Client, Version=4.13.15.0
How do I block a release using the Octopus.Client.dll in C#? I have been looking at the API, and I am not seeing it.
I am using Octopus.Client, Version=4.13.15.0
Is this it?
repository.Defects.RaiseDefect(release, “reason for block”);
The only reason I found this is this powershell https://gist.github.com/Dalmirog/4b45994a2c5f782fd0b4 which led me to look through the api for “Defects”
Bizarre. If this is it, why would it not be also visible on the release object?
Hi Tim,
Thank you for your question!
Yes, that API is the correct one for blocking a release. This API is the same one the UI calls when you use the “Prevent Progression” feature. Keep in mind that raising a defect won’t block the release completely - all the rules specified in our documentation on Blocking Deployments apply, which includes that the first lifecycle phase is always deployable to.
As for why Defects aren’t available on the Release repository, perhaps they should be! Since Defects are modelled as a separate resource to Releases, it makes sense for them to be available in their own repository in the Client. However, there is no reason they shouldn’t also be retrievable in the Releases repository, as Deployments are.
Thank you again for your question and feedback, and please let me know if I can assist you further.
Regards,
Jayden
TYVM Jayden. I also went through the documentation, and I would like to request a TRUE blocking mechanism. If I understand points 3 and 4 taken from the documentation correctly this is not a truly adequate block. I would expect and want a blocked release to be blocked from all environments, regardless of past deployments.
Would it be possible from a powershell step inserted at the beginning of the project to check for an active defect and throw an exception, essentially giving m what I want?
I looked over the variables https://octopus.com/docs/deployment-process/variables/system-variables and I see where I can get the releaseid, but not the defects. Would I have to resort to the rest API at that point?
I ended up writing some powershell that we will include as a step template into our projects. We do not want a blocked release to be deployable at all until any open defects are resolved. Including the powershell in case anyone else ever wants to do this as well:
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[string]$API_URL,
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[string]$API_KEY,
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[string]$RELEASE_ID
)
$headers = @{"X-Octopus-ApiKey"="$API_KEY";}
$result = Invoke-WebRequest "$API_URL/releases/$RELEASE_ID/defects" -Method Get -Headers $headers -UseBasicParsing
$defects = $result | ConvertFrom-Json
if ($defects -and $defects.TotalResults -gt 0) {
$openDefects = $defects.Items | Where-Object { $_.Status -eq 'Unresolved' }
if($openDefects){
$descriptions = ($openDefects | Select-Object -ExpandProperty Description)
$errs = "`r`n`t- " + [System.String]::Join("`r`n`t- ", $descriptions) + "`r`n "
throw "This release cannot be deployed. There are one or more open defects for this release: $errs"
} else {
Write-Output "No open defects found."
}
} else {
Write-Output "No defects found."
}
Hi Tim,
That’s an excellent solution! I’m glad you were able to use the API to meet your requirements.
Regards,
Jayden
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.