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

发布于 2025-01-11 15:03:28 字数 1212 浏览 0 评论 0原文

我正在尝试在 devOps yml 管道中使用 powershell 任务部署二头肌模板。

我有以下任务:

  - 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)" `

但是,当我运行它时,我收到以下错误消息:

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

我无法理解为什么文件路径未解析。我的文件结构是: 输入图片这里的描述

如果我部署 main.bicep 它可以工作,但在部署存储帐户模块时会失败。 任何帮助都会很棒。

I'm trying to deploy a bicep template using a powershell task in a devOps yml pipeline.

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:
enter image description here

It works if I deploy main.bicep but fails when deploying the storage account module.
Any help would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玩物 2025-01-18 15:03:28

部署作业不会自动克隆源存储库,因此您可以使用 Thomas 提到的工件方法,也可以添加 checkout: self 步骤。

来自文档:部署作业

部署作业不会自动克隆源存储库。你可以
使用 checkout: self 来检查您工作中的源存储库。
部署作业仅支持一个结账步骤。

在 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)" `

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.

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.
Deployment jobs only support one checkout step.

This would look like something like this inside the YAML pipeline:

  - 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)" `
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文