问题
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
回答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.
来源:https://stackoverflow.com/questions/55874974/how-to-execute-powershell-script-from-jenkins-by-passing-parameters