我有一个项目,看起来像这样:
project
|
├───src
│ Utility.groovy
│
└───vars
pipeline.groovy
script.ps1
在pipeline.groovy
中,我有一个实用程序对象:
def util = new Utility(this)
以及调用util.scriptCall(arg1: "1", arg2: "2", arg3: "3")
的步骤,其定义如下:
this.context.powershell returnStdout: true, script: ".\\script.ps1 -Arg1 ${args.arg1} -Arg2 ${args.arg2} -Arg3 ${args.arg3} -Workspace ${this.context.env.workspace}"
从我发现的所有东西中,我理所当然地正确地调用了它,但是我得到了以下错误:
.\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.
我已经安装了Powershell插件,但缺少与Jenkins相关的文档也无济于事。我已经将script.ps1
移到了src
文件夹中,甚至尝试为它创建一个scripts
文件夹,也得到了同样的结果。
你知道为什么我调用脚本会被解释为cmdlet吗?
发布于 2019-06-06 03:34:39
我只是个笨蛋。Workspace是正在构建的Git代码库。我不得不将脚本重新定位到该项目,它的工作与预期的一样。
发布于 2019-06-05 23:45:54
因为脚本在您试图调用脚本的位置不可用。
使用绝对路径调用脚本。如果路径包含空格,请使用调用运算符(&
)。
& "absolutePathToScript/script.ps1"
我不是百分之百确定,但Jenkins将通过$env:workspace
注入工作区(至少在正常的PowerShell构建步骤中会这样做),因此您可以通过以下方式调用脚本:
& "$($env:workspace)/vars/script.ps1"
https://stackoverflow.com/questions/56463404
复制相似问题