2016-09-23 4 views
1

에서 쉬 방법의 출력을 보내 내가 쉘 명령을 실행하는 Jenkinsfile을 가지고 있고 나는 slackSend 방법의 message:로 그 sh 방법의 출력을 보내려고합니다.캡처하고 Jenkinsfile

다음과 같은 내용이 있지만 슬랙 채널에 메시지가 비어 있습니다. 내가 메시지 섹션에서 참조 할 수있는 방식으로 출력을 캡처하는 방법을 확실하지 않다 : 좀 더 연구 한 후

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 메서드이면 여전히 실행되므로 정의 된 두 번째 함수는 필요하지 않습니다. 둘째, 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 
} 
관련 문제