2

I have configured a CI build for a Service Fabric application, in Visual Studio Team Services, according to this documentation: https://azure.microsoft.com/en-us/documentation/articles/service-fabric-set-up-continuous-integration.

However I've changed the deployment portion specified on the document above. As I want to deploy on my previously created remote azure cluster so I call the Deploy-FabricApplication.ps1 with the required parameters using power shell. But unfortunately this is not working. I'm getting the below error:

[void](Connect-ServiceFabricCluster @ClusterConnectionParameters) InvalidOperation: (:) [Connect-ServiceFabricCluster], FabricException FullyQualifiedErrorId : CreateClusterConnectionErrorId,Microsoft.ServiceFabric.Powershell.ConnectCluster

WARNING: Unable to Verify connection to Service Fabric cluster.

[error]Test-ServiceFabricClusterConnection : Cluster connection instance is null [error]At C:\Program Files\Microsoft SDKs\Service [error]Fabric\Tools\PSModule\ServiceFabricSDK\Publish-NewServiceFabricApplication.ps1:119 char:16 void : ResourceUnavailable: (:) [Test-ServiceFabricClusterConnection], NullReferenceException FullyQualifiedErrorId : GetClusterConnectionErrorId,Microsoft.ServiceFabric.Powershell.TestClusterConnection

I can deploy successfully using visual studio. Even if I run the Deploy-FabricApplication.ps1 from the build machine using power shell the application gets deployed without any error. But only if I run it using VSTS build step (part of CI), then the error mentioned above occurs.

Please note that as per the suggestion of Charisk on another stackoverflow thread I've modified the Deploy-FabricApplication.ps1 file to put the below line after line 169. $global:clusterConnection = $clusterConnection

This doesn't help either. Thanks in advance for your kind help.

user1814131
  • 259
  • 4
  • 16
  • Which task are you using to run the power-shell script? Powershell or Azure Powershell? Did you try the resolution in that thread: Using the "pure" powershell build task made sure that the script was executed using the . (dot) notation which worked like a charm.? – Eddie Chen - MSFT Apr 11 '16 at 08:17
  • I'm using Powershell – user1814131 Apr 11 '16 at 08:58
  • I think the problem is regarding with . (dot) notation. I just specified the path for the default Deploy-FabricApplication.ps1 in vsts build task. I also passed some parameters. How can I make sure that the script will be executed using dot notation? I believing invoking is the case in my scenario instead of dot sourcing. – user1814131 Apr 11 '16 at 11:49

2 Answers2

2

In your publish profile http://s30.postimg.org/bttleqitd/cloud.jpg you use StoreLocation="CurrentUser" but if you followed https://azure.microsoft.com/en-us/documentation/articles/service-fabric-set-up-continuous-integration and specifically the Import your automation certificate section under Set up your build machine then you probably have imported your certificate to the LocalMachine store location.

Simply change StoreLocation in your publish profile from CurrentUser to LocalMachine and you should be good to go.

jimmystormig
  • 10,672
  • 1
  • 29
  • 28
0

dot source notation means call the script with . "xxx.ps1". Refer to this link for details: PowerShell – What is dot sourcing and why use it?

enter image description here

Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60
  • I've already tried something like this. Used inline scripting for PowerShell task and used the following powershell command. . ./Deploy-FabricApplication.ps1 -ApplicationPackagePath 'C:\agent\_work\1\s\TestApp\pkg\Release' -PublishProfileFile 'C:\agent\_work\1\s\TestApp\PublishProfiles\Cloud.xml' -DeployOnly:$false -UnregisterUnusedApplicationVersionsAfterUpgrade $false -OverrideUpgradeBehavior 'None' -OverwriteBehavior 'SameAppTypeAndVersion' -ErrorAction Stop; The working directory was set to the script directory. No luck yet ! – user1814131 Apr 12 '16 at 06:25
  • @user1814131 Try with this format: (. './Deploy-FabricApplication.ps1'). The things between(). – Eddie Chen - MSFT Apr 12 '16 at 07:11
  • No luck... From the event viewer I got the following error: transport 0x17FA9CEFF0: failed to set security settings to { provider=SSL protection=EncryptAndSign store='CurrentUser/My' findValue='FindByThumbprint:9c3b3216282cf97d22c9f0518d268ee408a06e31' remoteCertThumbprints='9c3b3216282cf97d22c9f0518d268ee408a06e31' clientRoleEnabled=false claimBasedClientAuthEnabled=false }: CertificateNotFound – user1814131 Apr 12 '16 at 09:27
  • Here is the Error log in VSTS build: Connect-ServiceFabricCluster : An error occurred during this operation. Please check the trace logs for more details. At C:\agent\_work\2\s\TestApp\Scripts\Deploy-FabricApplication.ps1:172 char:16 + [void](Connect-ServiceFabricCluster @ClusterConnectionParameters) – user1814131 Apr 12 '16 at 09:57
  • Another parth of the error: + CategoryInfo : InvalidOperation: (:) [Connect-ServiceFabricCluster], FabricException + FullyQualifiedErrorId : CreateClusterConnectionErrorId,Microsoft.ServiceFabric.Powershell.ConnectCluster Test-ServiceFabricClusterConnection : Cluster connection instance is null – user1814131 Apr 12 '16 at 09:58
  • At C:\Program Files\Microsoft SDKs\Service Fabric\Tools\PSModule\ServiceFabricSDK\Publish-NewServiceFabricApplication.ps1:119 char:16 + [void](Test-ServiceFabricClusterConnection) + CategoryInfo : ResourceUnavailable: (:) [Test-ServiceFabricClusterConnection], NullReferenceException + FullyQualifiedErrorId : etClusterConnectionErrorId,Microsoft.ServiceFabric.Powershell.TestClusterConnection The error was long enough..so provided in these 3 comments – user1814131 Apr 12 '16 at 09:58
  • @user1814131 That's weird. I didn't have any issue at my side. I will do more investigation on this issue. By the way, I added my settings in the answer for a reference. – Eddie Chen - MSFT Apr 12 '16 at 10:00
  • I did exactly the same.. Here is the link of the image of vsts error - http://s29.postimg.org/kxo6zauon/Capture.jpg Is there anything to do with the certificates? I've imported the pfx file and copied it trusted people folder. Also granted the Network Service account permission to use my certificate. My store location is "CurrentUser". I don't have any clue to solve this problem. – user1814131 Apr 12 '16 at 10:06
  • Here is the image of cluster connection parameters used in cloud.xml http://s30.postimg.org/bttleqitd/cloud.jpg Here is the error I get in Event Viewer on the build VM http://s18.postimg.org/ei3y0egw9/error.jpg These are for your information. @Eddie - MSFT – user1814131 Apr 12 '16 at 10:15
  • @user1814131 According to the VSTS error logs, the issue is different with the dot notation issue. In your case, the connection is failed when connect to service farbic cluster, so when the powershell test the connection, it will get connection null error. Since you say there is no error when run the powershell script from build machine directly. I would recommend you to configure your build service to run with the account that you run the powershell script and try the deployment again. – Eddie Chen - MSFT Apr 13 '16 at 06:14
  • @user1814131 And you can also refer to this link to add the certification for network service account: http://stackoverflow.com/questions/5695339/how-do-you-install-a-certificate-in-a-pfx-file-in-to-the-personal-container-of-t – Eddie Chen - MSFT Apr 13 '16 at 06:23
  • What kind of build task are you using to invoke the PowerShell script? I believe that the basic PowerShell task does use dot sourcing while the Azure PowerShell task does not. – Matt Thalman May 25 '16 at 13:25