为什么我没有在Build Console中看到这个Jenkins文件的终端输出?

时间:2016-10-28 19:51:41

标签: jenkins jenkins-pipeline

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

#!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

1 个答案:

答案 0 :(得分:1)

缺少回显消息,因为public function index(){ return view('landing-page') ->with('title','Landing Page') ->with('query',Activity::with('projectModel')->get()) ->with('projects',Project::all()); } 只返回Undefined property: Illuminate\Database\Eloquent\Collection::$cv_project_name (View: C:\xampp\htdocs\PKL\netxcel-2-backup2\resources\views\landing-page.blade.php)的值而不执行包含echo的方法体。

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

以下可能的解决方法。

1.使用jenkinsSlack(type, channel=slack_channel())

slack_channel()注释
@NonCPS

2.事先确定slack_channel()并将其传递给默认参数@NonCPS def slack_channel() { try { if ('' != SLACK_CHANNEL) { return SLACK_CHANNEL } } catch (MissingPropertyException e) { return '#nathan-webhooks' } }

SLACK_CHANNEL