2016-05-06 7 views
0

私は、最初に引数番号チェック付きのコンソールアプリケーションを作成しました。そして、パッケージがデプロイされた後、デプロイメントPowerShellスクリプトの部分では、スクリプトをテストするために引数なしでこのアプリケーションを直接呼び出します。 Octopusは終了コードをキャプチャして、タスクログにキャプチャされたアプリからの出力がまったくないことを示しているようです。私は単にスクリプトで「エコー 『テスト』」あるいは単に「試験」の文字列を置く場合OctopusカスタムPowerShellスクリプトでコンソールアプリケーションの出力をキャプチャする方法は?

static void Main(string[] args) 
    { 
     if (args.Length < 4) 
     { 
      Console.WriteLine("Invalid argument number"); 
      Environment.ExitCode = -1; 
      return; 
     } 
    } 

ただし、出力はタコ展開タスクログに捕獲されました。どのようなアイデアは、スクリプトのコンソールアプリケーションを記録する正しい方法は何ですか?ありがとう。

答えて

0

申し訳ありませんが、Octopusの問題ではありません。実際には、.Net framework 4.6.1用に作成されたコンソールアプリケーションですが、触手サーバーは4.5.2しかありません。リモートデスクトップ経由でそのサーバー上でアプリケーションを実行すると、4.6.1 .Netフレームワークが見つからないというエラーメッセージが表示されます。 4.5.2でこの問題を修正してアプリを再構築してください。しかし、Octopusタスクログには何も関係していないので、これを見つけることは本当に難しかったです。これが将来他の人に役立つことを願っています。

0

「yourpowershellfile.ps1」という名前のファイルを作成するか、「eスクリプトを実行する」展開ステップを作成します。

は、あなたの代わりに「書き込み出力」試してみてください「書き込みホストを」タコは、タスクのログを配備見直し、OctopusDeployで

$FullPath = "C:\MyFolder" 
if ($OctopusEnvironmentName -ceq 'Development') 
{ 
    Write-Host "Console app will be execute" 
    & "$FullPath\yourconsolefile.exe" | Write-Host 
    Write-Host "Console app execution has finied" 
} 

このPowerShellを試してみてください。

+0

おかげで、しかし、私の問題は、実際にアプリケーションの私の目標は、4.6.1のために設定されているとして何のログは実際に存在しませんでした。ネットフレームワーク。触手には、アプリケーションの実行に失敗した.Netフレームワークがインストールされていません。現在のターゲットバージョンでビルドした後、Console.WriteLineは正しいジョブを実行します。 – bigbearzhu

0

Octopusの展開手順で実行される実行ファイルの後にコンソール出力を実際に取得する必要があるため、この質問が見つかった場合は、次のコードを使用できます。それは私がコンソール出力を必要とタコの手順accross私は喜んで再利用次の関数を書くために研究のビットを取った:

Function Invoke-CmdCommand{ 
    param(
     [parameter(Mandatory=$true)] 
     [ValidateNotNullOrEmpty()] 
     [ValidateScript({(Test-Path $_.Trim('"').Trim(''''))})] 
     [string]$Executable, 
     [string]$Parameters = '', 
     [switch]$CmdEscape 
    ) 
    BEGIN{ 
     Write-Verbose "Start '$($MyInvocation.Mycommand.Name)'" 
     $nl = [Environment]::NewLine 
     $exitCode = 0 
     $cmdOutput = [string]::Empty 
     # next line wrap string in quotes if there is a space in the path 
     #$Executable = (Format-WithDoubleQuotes $Executable -Verbose:$([bool]($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent))) 
     $command = "{0} {1}" -f $Executable, $Parameters 
     Write-Verbose "COMMAND: $command" 
     $terminatePrompt = "/C" # https://ss64.com/nt/cmd.html 
     $comSpec = $env:ComSpec 

     if($CmdEscape.IsPresent){ 
      $command = "`"$command`"" 
      Write-Verbose "ESCAPED COMMAND: $command" 
     }   
    } 
    PROCESS{ 
     $cmdResult = .{ 
      # script block exec: dot does not create local scope as opposed to ampersand 
      .$comSpec $terminatePrompt $command '2>&1' | Out-String | Tee-Object -Variable cmdOutput 
      return $LastExitCode 
     } 

     $exitCode = $cmdResult[$cmdResult.length-1] 

     if($exitCode -ne 0){ 
      Write-Host "FAILED with ExitCode: $exitCode; ERROR executing the command:$nl$command$nl" -ForegroundColor Red 
      Write-Host "ERROR executing the command:$nl$command" -ForegroundColor Yellow 
     }else{ 
      Write-Host "SUCCESSFULLY executed the command:$nl$command$nl" 
     }   
    } 
    END{ 
     if($Host.Version.Major -le 3){ 
     return ,$cmdOutput # -NoEnumerate equivalent syntax since it is not available in version 2.0 
     }else{ 
      Write-Output -NoEnumerate $cmdOutput 
     } 
     Write-Verbose "End '$($MyInvocation.Mycommand.Name)'"   
    } 
} 

USAGE:

Invoke-CmdCommand -Executable (Join-Path (Split-Path $env:ComSpec) ping.exe) -Parameters 'localhost' 

をOUTPUT:

Pinging localhost [::1] with 32 bytes of data:

Reply from ::1: time<1ms

Reply from ::1: time<1ms

Reply from ::1: time<1ms

Reply from ::1: time<1ms

Ping statistics for ::1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms

関連する問題