Service Fabric PowerShell Scripts

Last updated

You can use all of the features we provide for custom scripts, like using variables, passing parameters, publishing output variables and collecting artifacts.

The Service Fabric SDK must be installed on the Octopus Server. If this SDK is missing, the step will fail with an error: "Could not find the Azure Service Fabric SDK on this server."

PowerShell script execution may also need to be enabled. See the "Enable PowerShell script execution" section from the above link for more details.

After the above SDK has been installed, you will need to restart your Octopus service before the changes will take effect.

This step allows you to run Service Fabric SDK PowerShell cmdlets against your cluster. Once a connection has been established to your Service Fabric cluster, these cmdlets can be used to query or control various aspects of your cluster/applications.

Please see the Microsoft Service Fabric SDK documentation for available cmdlets.

Example

This example uses the Service Fabric SDK to query the health of an application, from the cluster that we've connected to.

# Hey, we can query things about our cluster because this PowerShell session
# is connected to our SF cluster and we have context!

# Determine the health of an application on our cluster.
$clusterApplication = "fabric:/MyServiceFabricApp"
$health = Get-ServiceFabricApplicationHealth -ApplicationName $clusterApplication
If ($health.AggregatedHealthState -eq "OK") {
    Write-Host "$($clusterApplication)'s health is ok!"
} Else {
    Write-Error "$($clusterApplication)'s health was found to be $($health.AggregatedHealthState)!  This is not ok :("
}

Connection Troubleshooting

Calamari uses the Connect-ServiceFabricCluster cmdlet to connect to your Service Fabric cluster. The connection parameters are logged (Verbose) at the time of a deployment to help if you need to debug connection problems to your Service Fabric cluster.

If you receive an error such as: "Unable to load DLL 'FabricCommon.dll': The specified module could not be found." and you have already installed the Service Fabric SDK on your server, the Octopus service may need to be restarted after this SDK has been installed. Please see the Service Fabric SDK documentation for more information.

If you are using a secure Service Fabric cluster and receive errors such as "An error occurred during this operation. Please check the trace logs for more details.", this is an error from Azure and may indicate that the Octopus Server was unable to connect to the Service Fabric cluster because of security reasons. If you are using Client Certificates for example, please ensure the client certificate is correctly installed on your Octopus Server in the LocalMachine (unless you have specifically overridden this store location).