Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
捕获并发送Jenkins文件中sh方法的输出_Jenkins_Groovy_Jenkins Plugins_Jenkins Pipeline - Fatal编程技术网

捕获并发送Jenkins文件中sh方法的输出

捕获并发送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

我有一个运行shell命令的Jenkinsfile,我想将
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
}
可能重复的