0

I have a powershell script in my Github. i am trying to execute that via Jenkins. Here is a part of the script :-

param (
+    [string]$fileDir = "%WORKSPACE%\src\Project\***",
 [string]$packagingDir = "%WORKSPACE%\src\packageTemp", 
 [string]$staticFilesToDeploy = "%WORKSPACE%\src\****"
  )

Now i am using a simple batch execution within Jenkins Job to run this script. I am trying to run it as

powershell -noexit "& ""%WORKSPACE%\src\***.ps1"""

But when Jenkins actually executes this powershell script its unable to replace %workspace% within the script and fails as it cannot find that. How do i make jenkins to replace that within the script when it executes it actually

2
  • I'm not into Jenkins, but shouldn't %WORKSPACE% rather be $WORKSPACE? The % characters are used in Windows batch commands. Commented Apr 27, 2019 at 13:35
  • Oh my bad, but even replacing it with $WORKSPACE, the powershell script is unable to extract exact value for it correctly Commented Apr 27, 2019 at 15:15

1 Answer 1

-1

I was able to get this resolved by passing arguments for the powershell script through jenkins :-

powershell.exe -file "%WORKSPACE%\src\***.ps1" -fileDir "%WORKSPACE%\src\Project\***" -packagingDir "%WORKSPACE%\src\packageTemp" -staticFilesToDeploy "%WORKSPACE%\src\****"

This force sets the values for the params within the script at run time and at the same time can be issued via jenkins to be able to make use of its environment variables.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.