繁体   English   中英

为什么在构建控制台中看不到该Jenkinsfile的终端输出?

[英]Why am I not seeing terminal output in the Build Console for this Jenkinsfile?

对于为什么我在此Jenkinsfile的jenkinsSlack()函数中看不到echo()语句的输出,我有些困惑。 这些阶段肯定正在运行,因为我可以在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
}

谢谢

由于jenkinsSlack(type, channel=slack_channel())仅返回slack_channel()的值,而不执行包含echo的方法主体jenkinsSlack(type, channel=slack_channel())因此缺少回显消息。

这是詹金斯特定于CPS转换的问题。 Jenkins管道脚本基于groovy,但在语法和用法方面有一些限制。 在此处查看更多详细信息: https : //github.com/jenkinsci/workflow-cps-plugin/blob/master/README.md#technical-design

可能的解决方法如下。

1,对slack_channel() @NonCPS注释

@NonCPS
def slack_channel() {
  try { if ('' != SLACK_CHANNEL) { return SLACK_CHANNEL } }
  catch (MissingPropertyException e) { return '#nathan-webhooks' }
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM