我正在尝试使用以下 yaml 脚本部署 Azure DevOps 管道
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- adf_publish
pool:
vmImage: ubuntu-latest
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
- task: AzurePowerShell@5
displayName: 'Azure PowerShell script: MyNewPreDeployment'
inputs:
azureSubscription: NewConnectionName
ScriptPath: '$(System.DefaultWorkingDirectory)/_Azure Data FactoryReName/drop/pre-and post-deployment.ps1'
ScriptArguments: '-armTemplate "$(System.DefaultWorkingDirectory)/_Azure Data FactoryReName/drop/ARMTemplateForFactory.json" -ResourceGroupName $(ResourceGroup) -DataFactoryName $(DataFactory) -predeployment $true -deleteDeployment $false'
azurePowerShellVersion: LatestVersion
但是我收到以下错误:
##[error]ENOENT: no such file or directory, stat '/home/vsts/work/1/s/_Azure Data FactoryReName/drop/pre-and post-deployment.ps1'
您似乎正在尝试使用 YAML 管道而不是发布管道来部署 ARM json 模板中定义的 ADF 实体。
管道定义中
$(System.DefaultWorkingDirectory)/_Azure Data FactoryReName/drop/pre-and post-deployment.ps1
的路径很可能是从发布管道复制的,其中包含工件 Azure Data FactoryReName
的存储库 drop
在 release 期间被 downloaded到
$(System.DefaultWorkingDirectory)
中。
但是,对于您的 YAML 管道,没有像发布管道中那样的下载工件步骤。脚本文件
pre-and post-deployment.ps1
和您的模板文件可能应该位于 $(System.DefaultWorkingDirectory)
中的某个路径下,而不是 $(System.DefaultWorkingDirectory)/_Azure Data FactoryReName/drop/
中,因为这些文件与 adf_publish
分支中的代码一起在 build 期间被 签出。
话虽如此,建议运行此命令
tree $(System.DefaultWorkingDirectory)
来确认脚本文件和ARM json模板的位置。
trigger:
- adf_publish
pool:
vmImage: ubuntu-latest
steps:
- script: |
tree $(System.DefaultWorkingDirectory)
displayName: Show file structure of System.DefaultWorkingDirectory during a build
- task: AzurePowerShell@5
displayName: 'Azure PowerShell script: MyNewPreDeployment'
inputs:
azureSubscription: $(NewConnectionName)
ScriptPath: '$(System.DefaultWorkingDirectory)/$(some-actual-path-to-script)/pre-and post-deployment.ps1'
ScriptArguments: '-armTemplate "$(System.DefaultWorkingDirectory)/$(some-actual-path-to-templates)/ARMTemplateForFactory.json" -ResourceGroupName $(ResourceGroup) -DataFactoryName $(DataFactory) -predeployment $true -deleteDeployment $false'
azurePowerShellVersion: LatestVersion
- task: AzureResourceManagerTemplateDeployment@3
inputs:
deploymentScope: 'Resource Group'
azureResourceManagerConnection: '$(NewConnectionName)'
subscriptionId: '$(AzureSub)'
action: 'Create Or Update Resource Group'
resourceGroupName: 'rg-azdatafactory'
location: 'Southeast Asia'
templateLocation: 'Linked artifact'
csmFile: '$(System.DefaultWorkingDirectory)/$(some-actual-path-to-templates)/ARMTemplateForFactory.json'
csmParametersFile: '$(System.DefaultWorkingDirectory)/$(some-actual-path-to-templates)/ARMTemplateParametersForFactory.json'
overrideParameters: '-factoryName "xxxxfactory-instance2" -AzureDataLakeStorage1_accountKey "$(StorageAccountKey)"'
deploymentMode: 'Incremental'
此外,您还可以考虑使用此任务
AzureResourceManagerTemplateDeployment@3
,它也适用于 YAML 管道,通常用于 ARM 部署。
有关如何定义管道目录变量的更多信息,请参考以下文档。