首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我在构建控制台中看不到这个Jenkinsfile的终端输出?

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

Stack Overflow用户
提问于 2016-10-29 03:51:41
回答 1查看 1.1K关注 0票数 0

我有点困惑,为什么在这个Jenkinsfile的jenkinsSlack()函数中看不到echo()语句的输出。阶段肯定在运行,因为我可以看到它们在管道可视化中执行。

代码语言:javascript
复制
#!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

EN

回答 1

Stack Overflow用户

发布于 2016-10-29 11:49:40

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

这是与CPS变换相关的Jenkins特有的问题。Jenkins管道脚本是基于groovy的,但是它在语法和用法方面有一些限制。点击此处查看更多详情:https://github.com/jenkinsci/workflow-cps-plugin/blob/master/README.md#technical-design

下面是可能的解决方法。

1.对slack_channel()使用@NonCPS注释

代码语言:javascript
复制
@NonCPS
def slack_channel() {
  try { if ('' != SLACK_CHANNEL) { return SLACK_CHANNEL } }
  catch (MissingPropertyException e) { return '#nathan-webhooks' }
}

2.提前确定SLACK_CHANNEL,并将其传递给默认参数channel

代码语言:javascript
复制
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
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40312316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档