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結果:

相關文章
相關標籤/搜索