如何通过传递参数从詹金斯执行Powershell脚本

如何通过传递参数从詹金斯执行Powershell脚本

本文介绍了如何通过传递参数从詹金斯执行Powershell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我的Github中有一个powershell脚本.我试图通过詹金斯执行.这是脚本的一部分:-

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\****"
  )

现在,我在Jenkins Job中使用简单的批处理执行来运行此脚本.我正在尝试以

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"""

但是,当Jenkins实际执行此powershell脚本时,它无法替换脚本中的%workspace%并失败,因为找不到该脚本.我如何让jenkins在实际执行脚本时替换脚本中的脚本

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

推荐答案

我能够通过jenkins传递powershell脚本的参数来解决此问题:-

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\****"

此力在运行时设置脚本中参数的值,同时可以通过jenkins发出以利用其环境变量.

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.

这篇关于如何通过传递参数从詹金斯执行Powershell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 09:00