4

I've got a project that looks like this:

project
|
├───src
│       Utility.groovy
│
└───vars
        pipeline.groovy
        script.ps1

In pipeline.groovy I have utility object:

def util = new Utility(this)

and a step that calls util.scriptCall(arg1: "1", arg2: "2", arg3: "3"), which is defined as:

this.context.powershell returnStdout: true, script: ".\\script.ps1 -Arg1 ${args.arg1} -Arg2 ${args.arg2} -Arg3 ${args.arg3} -Workspace ${this.context.env.workspace}"

From everything I've found I'm supposedly invoking this correctly, however I'm getting the following error:

.\script.ps1 : The term '.\script.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I've got the Powershell plugin installed but the lack of documentation for anything related to Jenkins isn't helping. I've moved script.ps1 into the src folder and even tried making a scripts folder for this with the same results.

Any idea why my invoking a script is getting interpreted as a cmdlet?

2
  • 1
    It means that it can't find that script in the "current directory" (.). Do you know what the current working directory is when you run that command? If not, maybe you can throw in a pwd or ls or something and try to see the output. Maybe the directory you're in is project and you'll need to call ./src/script.ps1 (PowerShell works fine with forward slashes / btw, in case you want to avoid having to escape backslashes all the time) Commented Jun 5, 2019 at 15:22
  • hey thanks for the / info! i was assuming that the workspace for jenkins would have been the vars directory but i'll mess around with the path and see if i can get anything. Commented Jun 5, 2019 at 15:29

2 Answers 2

3

Because the script is not available in the location, where you're trying to invoke the script.

Use the absolute path to invoke the script. If the path includes whitespaces use the call operator (&).

& "absolutePathToScript/script.ps1" 

I'm not hundred percent sure, but Jenkins will inject the workspace via $env:workspace (at least it will do so in normal PowerShell build steps), so you be able to invoke the script via:

& "$($env:workspace)/vars/script.ps1"
Sign up to request clarification or add additional context in comments.

1 Comment

The Workspace was the git repository so I ended up having to just relocate the script. Thanks for the helpful info though!
1

I'm just a ding dong. The Workspace was the Git repo that was getting built. I had to relocate the script to that project and it worked as expected.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.