最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Add a value from an Azure DevOps Pipeline Library variable to an Aspire .NET Container's Env Var - Stack Overflow

programmeradmin0浏览0评论

There is an Azure DevOps Pipeline that has variables set in a Library. There is a Library group per environment, for example, 'dev' and 'uat'. The pipeline uses YAML to create the resources for an Aspire .NET application, an Azure Container App, using Bicep templates.

Say there's a variable named email_address in the library group. This needs to be read into a container's env vars.

Firstly, it needs to be set in the pipeline as an env var:

          - task: AzureCLI@2
            displayName: Deploy Application
            inputs:
              azureSubscription: $(azureSubscription)
              scriptType: bash
              scriptLocation: inlineScript
              keepAzSessionActive: true
              inlineScript: |
                azd deploy --no-prompt
            env:
              EMAIL_ADDRESS: $(email_address)

So far, so good. The env var is created. Then there's a section in the "webfrontend.tmpl.yaml" doing this for the container:

  template:
    containers:
      - image: {{ .Image }}
        name: webfrontend
        env:
          - name: email-address
            value: {{ .Env.EMAIL_ADDRESS }}

I can't work out the syntax for getting the library variable through the pipeline yaml and into the container's env var.

ERROR: failed deploying service 'webfrontend': failed executing template file: template: manifest template:34:26: executing "manifest template" at <.Env.EMAIL_ADDRESS>: map has no entry for key "EMAIL_ADDRESS"

How do you do this?

There is an Azure DevOps Pipeline that has variables set in a Library. There is a Library group per environment, for example, 'dev' and 'uat'. The pipeline uses YAML to create the resources for an Aspire .NET application, an Azure Container App, using Bicep templates.

Say there's a variable named email_address in the library group. This needs to be read into a container's env vars.

Firstly, it needs to be set in the pipeline as an env var:

          - task: AzureCLI@2
            displayName: Deploy Application
            inputs:
              azureSubscription: $(azureSubscription)
              scriptType: bash
              scriptLocation: inlineScript
              keepAzSessionActive: true
              inlineScript: |
                azd deploy --no-prompt
            env:
              EMAIL_ADDRESS: $(email_address)

So far, so good. The env var is created. Then there's a section in the "webfrontend.tmpl.yaml" doing this for the container:

  template:
    containers:
      - image: {{ .Image }}
        name: webfrontend
        env:
          - name: email-address
            value: {{ .Env.EMAIL_ADDRESS }}

I can't work out the syntax for getting the library variable through the pipeline yaml and into the container's env var.

ERROR: failed deploying service 'webfrontend': failed executing template file: template: manifest template:34:26: executing "manifest template" at <.Env.EMAIL_ADDRESS>: map has no entry for key "EMAIL_ADDRESS"

How do you do this?

Share Improve this question edited Feb 5 at 21:27 Boggin asked Feb 5 at 17:26 BogginBoggin 3,4163 gold badges36 silver badges50 bronze badges 1
  • How do you pass environment variable to webfrontend.tmpl.yaml when deploy on your local machine? – Ziyang Liu-MSFT Commented Feb 6 at 7:59
Add a comment  | 

1 Answer 1

Reset to default 1

You can use extension Replace Tokens to replace tokens in text based files with variable values.

For example,

In your webfrontend.tmpl.yaml file:

  template:
    containers:
      - image: {{ .Image }}
        name: webfrontend
        env:
          - name: email-address
            value: {{ EMAIL_ADDRESS }}

Add a replacetokens@6 task before azd deploy in your pipeline YAML file:

- task: replacetokens@6
  inputs:
    sources: '{Path to your webfrontend.tmpl.yaml file}'
    tokenPattern: 'doublebraces'

In your variable group, add a variable named EMAIL_ADDRESS, then the value of email-address will be replaced with the value of variable EMAIL_ADDRESS.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论