簡體   English   中英

Github 操作 powershell:Posh-SSH session 錯誤

[英]Github actions powershell: Posh-SSH session error

我在 powershell 中編寫了用於部署項目的腳本。 我使用 Posh-SSH 上傳項目並在服務器上運行一些命令。 此腳本在本地計算機上工作,但是當我使用 Github 操作時 - 它會引發錯誤

Github 動作代碼

name: WebDeploy

on:
  push:
    branches:
    - main

jobs:
  build:

    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v2

    - name: Install required PowerShell modules
      shell: powershell
      run: |
          Set-PSRepository PSGallery -InstallationPolicy Trusted
          Install-Module Posh-SSH -ErrorAction Stop
    - name: Show that the Action works
      shell: powershell
      run: |
          Get-Module -Name Posh-SSH -ListAvailable | Select Path
          Import-Module Posh-SSH
    - name: Run deploy
      run: .\web-deploy-script.ps1
      shell: powershell

我正在安裝 Posh-SSH,並運行我的腳本。 我得到這個錯誤屏幕

New-SFTPSession : Object reference not set to an instance of an object.
At D:\a\projectfolder\web-deploy-script.ps1:24 char:16
+ ... tpSession = New-SFTPSession -ComputerName $HostIP -Credential $Creden ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Renci.SshNet.SftpClient:SftpClient) [New-SFTPSession], NullReferenceException
    + FullyQualifiedErrorId : SSH.NewSftpSession

我的腳本代碼

$secpasswd = ConvertTo-SecureString $Password -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential($User, $secpasswd)
$sftpSession = New-SFTPSession -ComputerName $HostIP -Credential $Credentials #error in this line

我該如何解決? 我需要這個腳本在本地和 Github 上工作

我在 powershell 中編寫了用於部署項目的腳本。 我使用 Posh-SSH 上傳項目並在服務器上運行一些命令。 此腳本在本地計算機上工作,但是當我使用 Github 操作時 - 它會引發錯誤

Github 動作代碼

name: WebDeploy

on:
  push:
    branches:
    - main

jobs:
  build:

    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v2

    - name: Install required PowerShell modules
      shell: powershell
      run: |
          Set-PSRepository PSGallery -InstallationPolicy Trusted
          Install-Module Posh-SSH -ErrorAction Stop
    - name: Show that the Action works
      shell: powershell
      run: |
          Get-Module -Name Posh-SSH -ListAvailable | Select Path
          Import-Module Posh-SSH
    - name: Run deploy
      run: .\web-deploy-script.ps1
      shell: powershell

我正在安裝 Posh-SSH,並運行我的腳本。 我得到這個錯誤屏幕

New-SFTPSession : Object reference not set to an instance of an object.
At D:\a\projectfolder\web-deploy-script.ps1:24 char:16
+ ... tpSession = New-SFTPSession -ComputerName $HostIP -Credential $Creden ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Renci.SshNet.SftpClient:SftpClient) [New-SFTPSession], NullReferenceException
    + FullyQualifiedErrorId : SSH.NewSftpSession

我的腳本代碼

$secpasswd = ConvertTo-SecureString $Password -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential($User, $secpasswd)
$sftpSession = New-SFTPSession -ComputerName $HostIP -Credential $Credentials #error in this line

我該如何解決? 我需要這個腳本在本地和 Github 上工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM