Running a shell command from a certain folder in the Jenkins' dynamic parameter script

I used the Jenkins' Dynamic parameter in order to generate date for a job but that is very easy to do.

What I needd to do latley is to get an application version using the javaScript's package manager's command npm or in other words, some shell command.

While googling, I have found that the way to run a shell command is as follows:

"<shell command>".execute().text. Problem was, I could only run the NPM command from the root of the JavaScript project and that wasn't my jenkins job's workspace so I needed to change folder into that folder first and that didn't work: "cd <folder>".execute(). To overcome this issue I fould the following solution:

"<some shell command>".execute(null, new File("<path to where you want to run the command from>")).text

 

The above overload of the execute function uses two parameters. The first one is irrelevant for this topic and the second one is actually what I needed. It sets the command to run under that path. 

 

Hope that helps someone.

 

Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com