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

一、使用背景

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

二、报错现象

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

1081775-20181023112151713-156103875.png

'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的问题

1081775-20181023112202458-534854652.png

你需要在上述的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启动的情况下,写入如下测试脚本:

1081775-20181023112207153-1329013334.png

你会得到如下的output结果:

1081775-20181023112211041-21673916.png

转载于:https://www.cnblogs.com/yangwenbo214/p/9835515.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值