Jenkins groovy pipeline - Need sout of command from executing jar file

∥☆過路亽.° 提交于 2019-12-02 04:20:56

You can execute a shell command from the pipeline script using sh step. The trick is to redirect the executed command's output to a file and then read it with readFile in the next step.

This should do what you want on linux slave:

sh "java -jar scalr-api.jar testing654 n1-standard-8 > scalr.out"
def out = readFile 'scalr.out'

On windows slave:

bat "java -jar scalr-api.jar testing654 n1-standard-8 > scalr.out"
def out = readFile 'scalr.out'
Jesse Glick

As of version 2.4 of Pipeline: Nodes and Processes it suffices to use:

def out = sh script: 'java -jar scalr-api.jar testing654 n1-standard-8', returnStdout: true
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!