Re: Pipeline: Shell step oddity removes escaped slash

2019-06-12 Thread 'Björn Pedersen' via Jenkins Users


Am Dienstag, 11. Juni 2019 13:14:28 UTC+2 schrieb Sverre Moe:
>
> I have the following Pipeline step to find specific files:
> sh("find . -regex '.*${packageName}-[0-9.]+-.\\.noarch\\.rpm'")
>
>
You' ll need to escape the backslashes twice: once for groovy and  once for 
the shell
sh("find . -regex '.*${packageName}-[0-9.]+-..noarch.rpm'")

Björn

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/6f206099-d137-488b-a67d-abf2c003d488%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Pipeline: Shell step oddity removes escaped slash

2019-06-11 Thread Sverre Moe
I have the following Pipeline step to find specific files:
sh("find . -regex '.*${packageName}-[0-9.]+-.\\.noarch\\.rpm'")

The Output:
[Pipeline] sh
+ find . -regex '.*package-name-[0-9.]+-.\.noarch\.rpm'
This does not return any result.

Both of these two works in Bash:
find . -regex '.*meos-dashboard-[0-9.]+-.\.x86_64\.rpm'
find . -regex .*meos-dashboard-[0-9.]+-.\.x86_64\.rpm

This groovy code work:
def find = "find . -regex .*package-name-[0-9.]+-.\\.noarch\\.rpm".execute()
println find.text

This groovy code does not work:
def find = "find . -regex '.*package-name-[0-9.]+-.\\.noarch\\.rpm'".execute
()
println find.text


So it seems Groovy does not work with surrounding the regex with single 
quote. Trying without does not go so well either:
sh("find . -regex .*${packageName}-[0-9.]+-.\\.noarch\\.rpm")

The output:
[Pipeline] sh
+ find . -regex '.*package-name-[0-9.]+-..noarch.rpm'
Pipeline seems to remove the "\" from the regular expression when I am not 
using the single quote.


Any idea what is the problem here? Pipeline or Groovy?

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/a8a22c0b-d707-4fdc-b41c-91e8b12d756a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.