Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

In Jenkins pipeline, what is the correct syntax to accept the passed-in parameter for this function?

I have a function that sets the NodeJS version.

def setNodeVersion(final String nodeVersion="11.15.0") {
  env.NODE_HOME = "${tool 'Node-"${nodeVersion}"'}"
  env.PATH="${env.NODE_HOME}/bin:${env.PATH}"
  sh """
    node -v
    npm -v
  """
}

setNodeVersion("12.22.1")

But when I call it, I get

ERROR: No tool named Node-"${nodeVersion}" found
Finished: FAILURE

What is the correct syntax?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

When you set NODE_HOME, you’re already inside a GString when invoking tool; no need for a second ${}.

Try env.NODE_HOME = "${tool ('Node-' + nodeVersion)}".

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading