简体   繁体   English

在詹金斯的bash脚本中没有回声

[英]No echos in bash script in Jenkins

I'm writing a Pipeline script for Jenkins on Mac that needs to execute a couple of sh steps. 我正在Mac上为Jenkins编写管道脚本,该脚本需要执行几个sh步骤。 Some of them involve RVM and Bundler ... 其中一些涉及RVM和Bundler ...

sh '#!/bin/bash -xl' +
    ' && rvm list' +
    ' && rvm use 2.3.1' +
    ' && gem install bundler' +
    ' && which bundler'

As you can see I have to use the hashbang to make RVM and Bundler to work, ie having to be in a Login Shell but the problem is I don't see any log output for this in Jenkins anymore, even with -xl flag. 如您所见,我必须使用hashbang来使RVM和Bundler正常工作,即必须位于Login Shell中,但问题是,即使使用-xl标志,我也不会在Jenkins中看到任何日志输出。

Does somebody know why log output is omitted and how to enable it for this? 有人知道为什么省略日志输出以及为此如何启用它吗?

UPDATE : 更新

sh returnStdout: true, script: '#!/bin/bash -xl && rvm list && rvm use 2.3.1 && gem install bundler && which bundler'

Log Output: 日志输出:

[Pipeline] sh
[app_ios_test_automation] Running shell script
[Pipeline] echo

The "sh" function has optional parameters. “ sh”功能具有可选参数。 If you call it like you're doing, you won't get the standard output of the script. 如果按您的方式进行调用,则不会获得脚本的标准输出。

If you go into your pipeline job definition, where you specify the pipeline script itself, you should see a link labeled "Pipeline Syntax". 如果进入管道作业定义(在其中指定管道脚本本身),则应该看到标有“管道语法”的链接。 This allows you to experiment with the pipeline steps that are enabled in your Jenkins instance. 这使您可以尝试在Jenkins实例中启用的管道步骤。 If you select "sh" from the dropdown and then click the "Advanced" button, you'll see the additional options you can set, including the "returnStdout" flag. 如果从下拉列表中选择“ sh”,然后单击“高级”按钮,您将看到可以设置的其他选项,包括“ returnStdout”标志。

为了扩展David Karr的答案,您可能正在寻找类似以下的内容:

sh(returnStdout: true, script: "your script here")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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