I am using the Jenkins file in the pipeline version 2.32.2.
For various reasons, I want to extract the version string from pom. I was hoping that I would not have to add the maven support plugin and use the evaluation.
I quickly came up with a little sed expression to get it out of pom, which uses pipes and runs on the command line in the jenkins workspace on the executor.
$ sed -n '/<version>/,/<version/p' pom.xml | head -1 | sed 's/[[:blank:]]*<\/*version>//g' 1.0.0-SNAPSHOT
It can probably be optimized, but I want to understand why the pipeline seems to fail when using shed commands. I played with various string formats, and currently I am using slashy string in dollars.
The pipeline step is as follows to provide easy command line output:
script { def ver_script = $/sed -n '/<version>/,/<version/p' pom.xml | head -1 | sed 's/[[:blank:]]*<\/*version>//g'/$ echo "${ver_script}" POM_VERSION = sh(script: "${ver_script}", returnStdout: true) echo "${POM_VERSION}" }
When running jenkins in the pipeline, I get the following console output, where it seems to separate the commands to be transferred into separate commands:
[Pipeline] script [Pipeline] { [Pipeline] echo sed -n '/<version>/,/<version/p' pom.xml | head -1 | sed 's/[[:blank:]]*<\/*version>//g' [Pipeline] sh [FRA-198-versioned-artifacts-44SD6DBQOGOI54UEF7NYE4ECARE7RMF7VQYXDPBVFOHS5CMSTFLA] Running shell script + sed -n /<version>/,/<version/p pom.xml + head -1 + sed s/[[:blank:]]*<\/*version>//g sed: couldn't write 89 items to stdout: Broken pipe [Pipeline] } [Pipeline] // script
Is there any guide on the proper use of commands with channels in a jenkins file?
source share