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

前端 未结 2 1263
梦毁少年i
梦毁少年i 2021-01-25 07:43

I am using Jenkins v:1.647 and the Pipeline plugin v: 1.14. My pipeline job pulls a groovy script which runs my orchestration. My issue is I have a executable jar that will perf

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-25 08:01

    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'
    

提交回复
热议问题