How to redirect stderr to Jenkins pipeline

I have this in my Jenkins file:

sh 'cat /opt/jenkins/workspace/JenkinsfileTest/testfile 2>/dev/null 

but it works as follows:

 [JenkinsfileTest] Running shell script + cat /opt/jenkins/workspace/JenkinsfileTest/testfile 

part of the redirect disappeared.

Is there something wrong with my team?

+5
source share
1 answer

Instead of suppressing the error output, you should avoid the error before it appears. Therefore, check if the file exists before its output:

 sh 'test -f testfile && cat testfile' 

must do the job.

0
source

Source: https://habr.com/ru/post/1264978/


All Articles