Jenkins中使用Azure Powershell连接Service Fabric报错not recognized的原因与解决办法

一、使用背景

在涉及Azure service Fabric的自动化应用场景中,依赖于Service Fabric的Azure Powershell cmdlets,我们可以使用Jenkins能实现cicd,当然VSTS也是一种选择。

二、报错现象

在Jenkins的Console output中,有如下报错:

'Connect-ServiceFabricCluster' is not recognized

三、报错原因

官网中是这么描述的:
If you try to run any of the Service Fabric PowerShell cmdlets, such as Connect-ServiceFabricCluster in an Azure PowerShell window, it fails, saying that the cmdlet is not recognized. The reason for this is that Azure PowerShell uses the 32-bit version of Windows PowerShell (even on 64-bit OS versions), whereas the Service Fabric cmdlets only work in 64-bit environments.

四、解决办法

我个人尝试过的解决办法有两种,第一种较为简单,推荐使用。第二种比较麻烦,需要下载JRE,需要改动jenkins的配置文件。

方法1:(实质是使用正确的Powershell.exe的路径为sysnative下)

我们在jenkins的configration下添加一个Environment variables 名称为path,在path中添加C:\Windows\sysnative\WindowsPowerShell\v1.0 为我们的powershell.exe的启动路径。

方法2:修改jenkins本身(解决方法可能值得商榷?慎用

我们需要下载JRE,进入Jenkins的配置文件目录C:\Program Files (x86)\Jenkins\jenkins.xml),做如下修改

<executable>C:\Program Files\Java\jre1.8.0_151\bin\java</executable> 
<executable>C:\ProgramData\Oracle\Java\javapath\java.exe</executable>

同样我们在jenkins的configration下添加一个Environment variables 名称为path,在path中添加C:\Windows\System32\WindowsPowerShell\v1.0 为我们的powershell.exe的启动路径。

五、旁支问题的解决方法

1. 如果上述过程后,你还遇到FabricCommon.dll could not be found的问题

你需要在上述的path中再加入C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code 对方法1而言:
最后你的Jenkins Environment variables path 应该是如下:

C:\Windows\sysnative\WindowsPowerShell\v1.0;C:\Windows\System32;C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code

2.做一个简单测试

创建一个Pipeline ,在你的local service fabric启动的情况下,写入如下测试脚本:

你会得到如下的output结果:

posted @ 2018-10-23 11:24  杨文波  阅读(356)  评论(0编辑  收藏  举报