Jenkins中使用Azure Powershell链接Service Fabric报错not recognized的缘由与解决办法

1、使用背景

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

2、报错现象

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

'Connect-ServiceFabricCluster' is not recognized测试

3、报错缘由

官网中是这么描述的:
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.this

4、解决办法

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

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

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

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

咱们须要下载JRE,进入Jenkins的配置文件目录C:\Program Files (x86)\Jenkins\jenkins.xml),作以下修改  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的启动路径。blog

5、旁支问题的解决方法

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

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

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

2.作一个简单测试

建立一个Pipeline ,在你的local service fabric启动的状况下,写入以下测试脚本:ci

你会获得以下的output结果:

相关文章
相关标签/搜索