[英]AzurePowerShell task cannot find filePath
I'm trying to run a PowerShell script in Azure Yaml Pipelines and I'm getting this error:我正在尝试在 Azure Yaml Pipelines 中运行 PowerShell 脚本,但出现此错误:
##[error]The term 'D:\a\1\s\myPowershellFile.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.
Code:代码:
jobs:
- deployment: Deploy
displayName: Deploy
environment: $(myEnvironment)
pool:
vmImage: 'windows-latest'
strategy:
runOnce:
deploy:
steps:
- task: AzurePowerShell@5
displayName: 'Run Powershell script'
inputs:
azureSubscription: $(azureConnectionName)
scriptType: filePath
scriptPath: './myPowershellFile.ps1'
azurePowerShellVersion: latestVersion
The file is pushed out to the repo for the branch that is triggering the build.该文件被推送到触发构建的分支的存储库。 I've also tried referencing the path explicitly with
$(Pipeline.Workspace)
and $(Build.SourcesDirectory)
.我还尝试使用
$(Pipeline.Workspace)
和$(Build.SourcesDirectory)
显式引用路径。 Version 4 also does not work.版本 4 也不起作用。 According to the docs this should be working!
根据文档,这应该可以工作!
Couldn't help noticing but you have used the forward slash "/" as the seperator for the filepath instead of a back-slash "\" like in the example you are pointing to in the azure docs:不禁注意到,但您使用正斜杠“/”作为文件路径的分隔符,而不是像您在 azure 文档中指向的示例中的反斜杠“\” :
- task: AzurePowerShell@5
inputs:
azureSubscription: my-arm-service-connection
scriptType: filePath
scriptPath: $(Build.SourcesDirectory)\myscript.ps1
This looks like the reason why.这似乎是原因。
There is a similar issue here.这里有一个类似的问题。 looks like it depends on whether you are using a windows or linux agent: cannot locate file in azure devops pipeline
看起来这取决于您使用的是 windows 还是 linux 代理: 在 azure devops 管道中找不到文件
After some more research I discovered this article which says that files are not automatically downloaded for deployment jobs.经过更多研究后,我发现这篇文章说部署作业不会自动下载文件。 I added this line, and that fixed the issue!
我添加了这一行,这解决了问题!
- checkout: self
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.