SamiM
SamiM

Reputation: 31

Jenkinsfile how to grep file name in variable

I have file in different server and that name will change. File: testfile-1.2-12345.sh ,"12345" is going to change.

How I get chancing text to variable?

In server machine this works and it's prints 12345:

ls ~/test/testfile* | awk -F'[-.s]' '{print $5}'

But when I do it from jenkins it wont work:

def versio = sh "ssh user@${ip} ls ~/test/testfile* | awk -F'[-.s]' '{print \$5}'"

It prints "12345" but if I try to print ${versio} it shows null.

Upvotes: 1

Views: 5223

Answers (1)

FCh
FCh

Reputation: 677

Your command is correct. But in pipeline you need to specify returnStdout:true. Detailed documentation is here.

def versio = sh returnStdout: true, script: 'ssh user@${ip} ls ~/test/testfile* | awk -F\'[-.s]\' \'{print \\$5}\''

Upvotes: 1

Related Questions