Jenkins pipeline sh does not seem to respect pipe in shell command

前端 未结 6 1259
清歌不尽
清歌不尽 2020-12-15 20:29

I am using a Jenkinsfile in a pipeline on version 2.32.2.

For various reasons I want to extract the version string from the pom. I was hoping I wouldn\'t have to a

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-15 21:13

    I know this kind of late answer, but whoever you who needs the solution without eval you can use /bin/bash -c "script" to make pipe works

    script {
        POM_VERSION = sh(script: "/bin/bash -c 'sed -n \'//,///g\'\''", returnStdout: true)
        echo "${POM_VERSION}"
    }
    

    The only problem with this method is hellish escape yet this way the subshell of pipe will be handled by our boy /bin/bash -c

提交回复
热议问题