捕获并发送Jenkins文件中sh方法的输出
我有一个运行shell命令的Jenkinsfile,我想将捕获并发送Jenkins文件中sh方法的输出,jenkins,groovy,jenkins-plugins,jenkins-pipeline,Jenkins,Groovy,Jenkins Plugins,Jenkins Pipeline,我有一个运行shell命令的Jenkinsfile,我想将sh方法的输出作为slackSend方法的消息发送出去 到目前为止,我有以下内容,但是发送给slack通道的消息是空的。我不确定如何在消息部分引用输出: node { checkout scm stage 'run shell command' def shell_command = sh "ls -l" def shell_output = apply_cluste
sh
方法的输出作为slackSend
方法的消息发送出去
到目前为止,我有以下内容,但是发送给slack通道的消息是空的。我不确定如何在消息部分引用输出:
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
}
在进一步研究之后,我发现了一些我最初并不了解的事情:第一,即使在Jenkins文件中定义了一个函数,如果它是像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
}
可能重复的