您当前的位置: 首页 >  jenkins

qq_34412985

暂无认证

  • 6浏览

    0关注

    1061博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Jenkins Tips:去掉pipeline中shell命令的调试信息

qq_34412985 发布时间:2020-06-07 18:19:39 ,浏览量:6

在Jenkins的Console Output中有时会看到‘+’开头的shell命令调试信息,看起来比较混乱。原因是Jenkins默认用‘-xe’的选项去运行‘sh’命令。例如如下pipeline会产生后续的输出。

pipeline {
    agent none
    stages {
        stage('Example') {
            steps {
                node('master') {
                    sh 'dmesg | grep raspberrypi | grep soc' 
                }
            }
        }
    }
}

输出:

[Pipeline] sh
+ dmesg
+ grep raspberrypi
+ grep soc

解决方法是自定义一个运行shell脚本的函数,并在每个命令行前加入‘#!/bin/sh -e\n’选项。

def mysh(cmd, returnStatus) {
    return sh (script: '#!/bin/sh -e\n'+ cmd, returnStatus: returnStatus)
}

pipeline {
    agent none
    stages {
        stage('Example') {
            steps {
                node('master') {
                    mysh ('dmesg | grep raspberrypi | grep soc', true)
                }
            }
        }
    }
}

参考链接:https://stackoverflow.com/questions/39891926/how-to-disable-command-output-in-jenkins-pipeline-build-logs

关注
打赏
1653291990
查看更多评论
立即登录/注册

微信扫码登录

0.0490s