简体   繁体   中英

Getting groovy syntax issue in my Jenkins pipeline

I have a simple script that i need for my pipeline :-

 sh '''podname=$(kubectl get pods -n my-namespace --template '{{range .items}}{{.metadata.name}}{{"\\n"}}{{end}}' | grep my-pod) echo "my name is $podname"'''

All i need to invoke through my jenkins declarative pipeline is the value of that kubectl command that i can use later in my script. If i run the same directly on the linux server it works just fine, but somehow through groovy shell invocation always results in syntax errors with respect to unterminated quotes, illegal dollar literal, etc. How do i fix this?

The syntax looks fine to me, except for this, in the middle of the command:

"\n"

This will be interpreted as an actual new-line, which may not be what you want? Perhaps try this instead, to let the \\n sequence be passed to the command:

"\\n"

If that still doesn't help... according to the docs :

Runs a Bourne shell script, typically on a Unix node. Multiple lines are accepted. 

An interpreter selector may be used, for example: #!/usr/bin/perl

So another suggestion is to try adding the appropriate shebang to your script... as there's no reason the result should be different from when you run this on the shell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM