I have issues extracting stdout to get only the result, last(second line).
i have jenkins pipeline using groovy script which executes the following:
stage('Generate'){
stdout = bat([
returnStdout: true,
script: 'C:/folder/generate.exe --environment %ENVIRONMENT% --optionalproperties %OPTIONALPROPS%',
encoding: 'UTF-8'
]).trim();
if i pass echo stdout, to capture what this command generated, i get stdout as -
C:\folder2\folder2>C:/folder1/generate.exe --environment PROD --optionalproperties something 12345678
So my result is in new line, 12345678. I need to capture only this.
I used before to do this with: result = stdout.readLines().drop(1).split(" ") and i was getting just the 12345678. But it stopped working somehow.
I managed to find a workaround with this:
result = stdout.reverse().take(8).reverse()
which takes last 8 numbers and extracts them. But it's not good solution as i might have more or less amount of numbers generated, so i need a proper way to extract it.
Any advise guys what i could try else as i dont get why readLines() fails to get me any result, though the batch command didnt change?
In other words you need to get last word of output. So you can do:
result = stdout.tokenize().last()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With