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

前端 未结 2 1259
梦毁少年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'
    
    0 讨论(0)
  • 2021-01-25 08:10

    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
    
    0 讨论(0)
提交回复
热议问题