不能 运行 来自 Yaml Azure Devops 管道的脚本
Can't run a script from a Yaml Azure Devops pipeline
我的 Yaml Azure Devops 管道在 运行 运行脚本时失败。
情况
我在 Tuto-BuildDeploy 存储库中有这个脚本:
trigger:
- none
pool:
vmImage: windows-latest
resources:
repositories:
- repository: TutoDeploy
ref: main
type: git
name: Tuto-Deploy
jobs:
- job: checkout
steps:
- checkout: self
- checkout: TutoDeploy
- job: Deploy
dependsOn:
- checkout
steps:
- task: AzurePowerShell@5
inputs:
azureSubscription: 'ToAzureCnx'
ScriptType: 'FilePath'
ScriptPath: .\Tuto-Deploy\build.ps1
azurePowerShellVersion: 'LatestVersion'
这是我的构建。ps1 文件:
param
(
)
$resourceGroup = "RG2"
$location = "westeurope"
New-AzResourceGroup -Name $resourceGroup -Location $location -Force
发生了什么
我收到此错误消息:
##[error]The term 'D:\a\s\Tuto-Deploy\build.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.
我测试了什么
我补充说:
- script: dir $(Build.SourcesDirectory)\Tuto-Deploy
检查构建。ps1是否已下载。
我还尝试从项目中的管道 运行 Tuto-Deploy:
trigger:
- main
pool:
vmImage: windows-latest
steps:
- task: AzurePowerShell@5
inputs:
azureSubscription: 'ToAzureCnx'
ScriptType: 'FilePath'
ScriptPath: '$(System.DefaultWorkingDirectory)/build.ps1'
azurePowerShellVersion: 'LatestVersion'
它工作正常。
所以我认为脚本没有问题。
我需要的
我不明白为什么它不起作用。我该怎么办?
谢谢
您 运行 在单独的作业中执行结帐步骤。这导致了问题。
每份工作都会 运行 加入全新的代理。参见 here。因此,在第一份工作中下载的 TutoDeploy 存储库在第二份工作中不可访问。您应该将结帐作业与部署作业结合起来。如果只需要在结帐步骤成功时执行,您可以为 AzurePowershell 任务设置条件。见下文:
- job:
steps:
- checkout: self
- checkout: TutoDeploy
- task: AzurePowerShell@5
inputs:
azureSubscription: 'ToAzureCnx'
ScriptType: 'FilePath'
ScriptPath: .\Tuto-Deploy\build.ps1
azurePowerShellVersion: 'LatestVersion'
condition: succeeded()
我的 Yaml Azure Devops 管道在 运行 运行脚本时失败。
情况
我在 Tuto-BuildDeploy 存储库中有这个脚本:
trigger:
- none
pool:
vmImage: windows-latest
resources:
repositories:
- repository: TutoDeploy
ref: main
type: git
name: Tuto-Deploy
jobs:
- job: checkout
steps:
- checkout: self
- checkout: TutoDeploy
- job: Deploy
dependsOn:
- checkout
steps:
- task: AzurePowerShell@5
inputs:
azureSubscription: 'ToAzureCnx'
ScriptType: 'FilePath'
ScriptPath: .\Tuto-Deploy\build.ps1
azurePowerShellVersion: 'LatestVersion'
这是我的构建。ps1 文件:
param
(
)
$resourceGroup = "RG2"
$location = "westeurope"
New-AzResourceGroup -Name $resourceGroup -Location $location -Force
发生了什么
我收到此错误消息:
##[error]The term 'D:\a\s\Tuto-Deploy\build.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.
我测试了什么
我补充说:
- script: dir $(Build.SourcesDirectory)\Tuto-Deploy
检查构建。ps1是否已下载。
我还尝试从项目中的管道 运行 Tuto-Deploy:
trigger:
- main
pool:
vmImage: windows-latest
steps:
- task: AzurePowerShell@5
inputs:
azureSubscription: 'ToAzureCnx'
ScriptType: 'FilePath'
ScriptPath: '$(System.DefaultWorkingDirectory)/build.ps1'
azurePowerShellVersion: 'LatestVersion'
它工作正常。
所以我认为脚本没有问题。
我需要的
我不明白为什么它不起作用。我该怎么办?
谢谢
您 运行 在单独的作业中执行结帐步骤。这导致了问题。
每份工作都会 运行 加入全新的代理。参见 here。因此,在第一份工作中下载的 TutoDeploy 存储库在第二份工作中不可访问。您应该将结帐作业与部署作业结合起来。如果只需要在结帐步骤成功时执行,您可以为 AzurePowershell 任务设置条件。见下文:
- job:
steps:
- checkout: self
- checkout: TutoDeploy
- task: AzurePowerShell@5
inputs:
azureSubscription: 'ToAzureCnx'
ScriptType: 'FilePath'
ScriptPath: .\Tuto-Deploy\build.ps1
azurePowerShellVersion: 'LatestVersion'
condition: succeeded()