Bad Substitution error while passing Jenkins Parameter value in shell script inside Declarative pipeline

Viewed 204

Here is my code which I am passing parameter value in my Jenkins Declarative Pipeline, but when I execute getting this error

T@tmp/durable-64ccbb6b/script.sh: line 4: ${params.InputValue}: bad substitution

                  sh '''
                  #!/bin/bash -xe
                  printf '%s\n' /dev/sd{e..z} | head -n "${params.InputValue}" > volumelist.txt
                  cat volumelist.txt
                  '''

I tried almost all of google searches for Bad substitution. Still can't get rid of it. Could someone help me out how to resolve this??

1 Answers

Have a look at Groovy's string interpolation.

tl;dr Use """ instead of ''':

sh """
  printf ${params.InputValue}
"""
Related