How to execute powershell script from jenkins by passing parameters

℡╲_俬逩灬. 提交于 2019-12-24 22:53:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!