[英]Why am I not seeing terminal output in the Build Console for this Jenkinsfile?
I'm a little confused as to why I am not seeing the output from the echo() statements in the jenkinsSlack() function in this Jenkinsfile. 对于为什么我在此Jenkinsfile的jenkinsSlack()函数中看不到echo()语句的输出,我有些困惑。 The stages are definitely running as I can see them executing in the Pipeline visualization.
这些阶段肯定正在运行,因为我可以在Pipeline可视化中看到它们正在执行。
#!groovy
def slack_channel() {
try { if ('' != SLACK_CHANNEL) { return SLACK_CHANNEL } }
catch (MissingPropertyException e) { return '#nathan-webhooks' }
}
// simplify the generation of Slack notifications for start and finish of Job
def jenkinsSlack(type, channel=slack_channel()) {
echo("echo 'In jenkinsSlack()...")
echo("echo 'type specified as : ${type}'")
echo("echo 'channel specified as : ${channel}'")
if ( 'SUCCESS' == currentBuild.result ) {
slackSend channel: channel, color: 'good', message: "type: ${type}"
} else if ( 'FAILURE' == currentBuild.result ) {
slackSend channel: channel, color: 'danger', message:"type: ${type}"
} else {
slackSend channel: channel, color: 'warning', message: "type: ${type}"
}
// node - action starts here
node {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm', 'defaultFg': 2, 'defaultBg':1]) {
stage ("send Slack start message") {
checkout scm
jenkinsSlack('start')
}
stage("send Slack finish message") {
jenkinsSlack('finish')
}
} // AnsiColorBuildWrapper
}
Thx 谢谢
Echo messages are missing because jenkinsSlack(type, channel=slack_channel())
just returns the value of slack_channel()
without executing the method body including echo. 由于
jenkinsSlack(type, channel=slack_channel())
仅返回slack_channel()
的值,而不执行包含echo的方法主体jenkinsSlack(type, channel=slack_channel())
因此缺少回显消息。
This is Jenkins specific problem related to CPS transform. 这是詹金斯特定于CPS转换的问题。 Jenkins pipeline script is based on groovy but it has some constraints with regard to its syntax and usage.
Jenkins管道脚本基于groovy,但在语法和用法方面有一些限制。 See more details here: https://github.com/jenkinsci/workflow-cps-plugin/blob/master/README.md#technical-design
在此处查看更多详细信息: https : //github.com/jenkinsci/workflow-cps-plugin/blob/master/README.md#technical-design
Possible workarounds below. 可能的解决方法如下。
1.Use @NonCPS
annotation for slack_channel()
1,对
slack_channel()
@NonCPS
注释
@NonCPS
def slack_channel() {
try { if ('' != SLACK_CHANNEL) { return SLACK_CHANNEL } }
catch (MissingPropertyException e) { return '#nathan-webhooks' }
}
2.determine SLACK_CHANNEL
in advance and pass it to the default argument channel
: 2.预先确定
SLACK_CHANNEL
并将其传递给默认参数channel
:
def slack_channel() {
try { if ('' != SLACK_CHANNEL) { return SLACK_CHANNEL } }
catch (MissingPropertyException e) { return '#nathan-webhooks' }
}
SLACK_CHANNEL = slack_channel()
def jenkinsSlack(type, channel=SLACK_CHANNEL) {
echo type
echo channel
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.