简体   繁体   English

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

[英]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.

相关问题 找不到任何要构建的修订版。 验证此作业的存储库和分支配置。 为什么我看到这个失败? - Couldn't find any revision to build. Verify the repository and branch configuration for this job. Why am I seeing this failure? 在终端使用 curl 调用构建后,如何在终端构建期间查看 Jenkins 控制台输出? - How to view Jenkins console output during a build from the terminal after invoking build using curl from the terminal? 使用Jenkins脚本控制台并查看Groovy输出 - Using Jenkins script console and seeing the Groovy output Jenkinsfile如何从控制台输出中提取值? - How can Jenkinsfile extract value from console output? 我可以使用 Jenkinsfile 中的函数构建阶段吗? - Can I build stages with a function in a Jenkinsfile? 为什么我在 Jenkins 构建中收到 ClassCastException - Why am I getting ClassCastException in Jenkins build 我如何使用 cron 语法从 jenkinsfile 触发构建? - How i can trigger build from jenkinsfile using cron syntax? 如何将命令的输出转换为Jenkinsfile中的环境变量? - How can I get the output of a command into an environmental variable in a Jenkinsfile? 在 Jenkinsfile 中对 ECR 进行授权,以便我可以提取图像来运行构建? - Auth into ECR in a Jenkinsfile so I can pull an image to run the build in? Jenkinsfile 构建日志 - Jenkinsfile build log
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM