2016-09-23 6 views
1

シェルコマンドを実行中のJenkinsfileがあり、slackSendメソッドのmessage:としてそのshメソッドの出力を送信したいとします。Jenkinsfileのshメソッドから出力をキャプチャして送信する

これまでのところ、私はスラックチャンネルへのメッセージが空です。私はメッセージセクションでそれを参照することができるように、出力をキャプチャする方法かどうか分からない:

node { 

     checkout scm 

     stage 'run shell command' 

     def shell_command = sh "ls -l" 
     def shell_output = apply_cluster 

     stage 'notify slack-notification' 
     slackSend channel: '#slack-notifications', color: 'good', message:  shell_output, teamDomain: 'company', token: env.SLACK_TOKEN 
} 
+0

可能な重複[ジェンキンスパイプラインプラグイン:シェルを実行し、出力を解析します](http://stackoverflow.com/questions/36304131/jenkins-pipeline-plugin-execute-shell-パース出力) – Pom12

答えて

1

もう少し研究の後、私は私が最初に理解していなかった物事のカップルを発見:最初にJenkinsfileで関数を定義しても、それがshのようなDSLメソッドなら、それはまだ実行されるので、私が定義した2番目の関数は必要ないということです。次に、stdoutを返す場合は、コマンドの一部として指定する必要があります。新しいコードは次のようになります。

node { 

     checkout scm 

     stage 'run shell command' 

     def shell_command = sh script: "ls -l", returnStdout: true 

     stage 'notify slack-notification' 
     slackSend channel: '#slack-notifications', color: 'good', message: shell_command, teamDomain: 'company', token: env.SLACK_TOKEN 
} 
関連する問題