简体   繁体   English

Bicep 部署错误:读取文件时出错。 找不到路径“/home/vsts/work/1/s/bicep/storageaccount.bicep”的一部分

[英]Bicep Deployment error : An error occurred reading file. Could not find a part of the path '/home/vsts/work/1/s/bicep/storageaccount.bicep'

I'm trying to deploy a bicep template using a powershell task in a devOps yml pipeline.我正在尝试在 devOps yml 管道中使用 powershell 任务部署二头肌模板。

I have the following task:我有以下任务:

  - task: AzurePowerShell@4
    displayName: "4.3) Deploy xxxxxx Synapse Infra"
    enabled: true
    inputs:
      azureSubscription: ${{parameters.azureServiceConnection}}
      ScriptType: "InlineScript"
      azurePowerShellVersion: "LatestVersion"
      continueOnError: true
      errorActionPreference : "continue"
      Inline: |
        echo "Deploy Bicep template"
        $deployment = New-AzResourceGroupDeployment `
          -ResourceGroupName "rg-emdi-data-${{parameters.environment}}" `
          -TemplateFile "$env:BUILD_SOURCESDIRECTORY\bicep\storageaccount.bicep" `
          -envName "${{parameters.environment}}" `
          -location "${{parameters.location}}" `
          -storageId "$(storageID)" `

However, when I run it, I get the following error message:但是,当我运行它时,我收到以下错误消息:

ERROR: An error occurred reading file. Could not find a part of the path '/home/vsts/work/1/s/bicep/storageaccount.bicep'.

I can't understand why the file path is not resolved.我不明白为什么文件路径没有解析。 My file structure is:我的文件结构是: 在此处输入图像描述

It works if I deploy main.bicep but fails when deploying the storage account module.如果我部署 main.bicep 但在部署存储帐户模块时失败,它会起作用。 Any help would be great.任何帮助都会很棒。

A deployment job does not automatically clone the source repo, so you can either use the artifact approach as mentioned by Thomas or you can add a checkout: self step.部署作业不会自动克隆源代码库,因此您可以使用 Thomas 提到的工件方法,也可以添加一个checkout: self步骤。

From the documentation: Deployment Jobs来自文档: 部署作业

A deployment job doesn't automatically clone the source repo.部署作业不会自动克隆源代码库。 You can checkout the source repo within your job with checkout: self.您可以使用 checkout: self 在您的工作中检出源代码库。 Deployment jobs only support one checkout step.部署作业仅支持一个结帐步骤。

This would look like something like this inside the YAML pipeline:这在 YAML 管道中看起来像这样:

  - stage: Deployment
    jobs:
      - deployment: DeployBicep
        environment: $(Environment)
        strategy:
          runOnce:
            deploy:
              steps:
                - checkout: self
                - task: AzurePowerShell@4
                  displayName: "4.3) Deploy xxxxxx Synapse Infra"
                  enabled: true
                  inputs:
                    azureSubscription: ${{parameters.azureServiceConnection}}
                    ScriptType: "InlineScript"
                    azurePowerShellVersion: "LatestVersion"
                    continueOnError: true
                    errorActionPreference : "continue"
                    Inline: |
                      echo "Deploy Bicep template"
                      $deployment = New-AzResourceGroupDeployment `
                        -ResourceGroupName "rg-emdi-data-${{parameters.environment}}" `
                        -TemplateFile "$env:BUILD_SOURCESDIRECTORY\bicep\storageaccount.bicep" `
                        -envName "${{parameters.environment}}" `
                        -location "${{parameters.location}}" `
                        -storageId "$(storageID)" `

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM