我有一个带有一个容器的Deployment.yml文件,如下所示:
apiVersion: apps/v1
kind: Deployment
[...]
spec:
containers:
- name: my-app
image: acr/my-app:1.0 #-> should be completly overridden!
和执行Azure构建/推送并应部署我的应用程序的Azure DevOps作业:
variables:
imageRepository: 'my-app'
containerRegistry: 'acr'
dockerfilePath: '$(Build.SourcesDirectory)/myapp/Dockerfile'
tag: '$(Build.BuildId)'
[...]
- task: KubernetesManifest@0
displayName: Deploy on kubernetes cluster
inputs:
action: 'deploy'
kubernetesServiceConnection: '...'
namespace: 'default'
manifests: '$(Build.SourcesDirectory)/deployment.yml'
containers: |
$(containerRegistry)/$(imageRepository):$(tag)
我希望覆盖Deployment.yml中的完整映像参考值。但是我不知道如何编写一个有效的占位符。我尝试了很多不同的方法,从$(VALUE)
到VALUE
到``{{VALUE}},例如:
image: ${{ variables.containerRegistry }} / ${{ variables.imageRepository }} : ${{ variables.tag}}
。但是,占位符根本没有被替换,并且容器因无效的图像参照而失败。
Azure DevOps可以执行此操作吗?还是我需要通过bash任务或类似方法覆盖映像值?
更新
为阐明我的要求:
我想覆盖完整的字符串,因为我想在多个阶段重用该文件,其中只有注册表的标记很难。例如:acr1/my-app:tag1
和acr2/my-app:tag2
答案 0 :(得分:2)
The fully qualified URL of the image to be used for substitutions on the manifest files. This input accepts the specification of multiple artifact substitutions in newline-separated form. Here's an example:
containers: |
contosodemo.azurecr.io/foo:test1
contosodemo.azurecr.io/bar:test2
In this example, all references to contosodemo.azurecr.io/foo and contosodemo.azurecr.io/bar are searched for in the image field of the input manifest files. For each match found, the tag test1 or test2 replaces the matched reference.
您需要确保清单中的字符串与KubernetesManifestTask中的Registry / image:tag字符串匹配
Azure DevOps填充匹配的注册表/图像并更新标签部分