所以我采用了系统生成的azure-pipelines.yml,现在我将它分成build.yaml和deployment.yaml,它们在Azure DevOps中都有自己的管道。
我已经向production分支添加了分支和构建验证,因此需要将PR合并到其中。创建PR时,它会自动运行Build,从而运行build.yaml管道。
如果通过,则可以审批并合并到production中。然后,合并触发Deployment,从而触发deployment.yaml管道。
Build正在工作。Deployment不是,原因是它找不到k8s清单...基本上,这一部分在系统中生成azure-pipelines.yml
- upload: k8s
artifact: k8s以下是自动生成的内容的完整上下文:
trigger:
- production
resources:
- repo: self
variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: '<GUID>'
imageRepository: 'app'
containerRegistry: 'appacr.azurecr.io'
dockerfilePath: '$(Build.SourcesDirectory)'
tag: '$(Build.BuildId)'
imagePullSecret: 'appacr1c5a-auth'
# Agent VM image name
vmImageName: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push an api image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)-api
dockerfile: $(dockerfilePath)/api/Dockerfile
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
- upload: k8s
artifact: k8s
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
jobs:
- deployment: Deploy
displayName: Deploy
pool:
vmImage: $(vmImageName)
environment: 'App Production AKS'
strategy:
runOnce:
deploy:
steps:
- task: KubernetesManifest@0
displayName: Create imagePullSecret
inputs:
action: createSecret
secretName: $(imagePullSecret)
kubernetesServiceConnection: 'App Production AKS'
dockerRegistryEndpoint: $(dockerRegistryServiceConnection)
- task: KubernetesManifest@0
displayName: Deploy to api Kubernetes cluster
inputs:
action: deploy
kubernetesServiceConnection: 'App Production AKS'
manifests: |
$(Pipeline.Workspace)/k8s/aks/api.yaml
imagePullSecrets: |
$(imagePullSecret)
containers: |
$(containerRegistry)/$(imageRepository)-api:$(tag)这是我如何将其拆分的方法:
# build.yaml (works)
trigger: none
resources:
- repo: self
variables:
- template: templates/variables.yaml
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push an api image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)-api
dockerfile: $(dockerfilePath)/api/Dockerfile
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
- upload: k8s
artifact: k8s还有..。
# deployment.yaml (does not work)
trigger:
branches:
include:
- production
resources:
- repo: self
variables:
- template: templates/variables.yaml
stages:
# - template: templates/changed.yaml
- stage: Deploy
displayName: Deploy stage
# dependsOn: Build
jobs:
- deployment: Deploy
displayName: Deploy
pool:
vmImage: $(vmImageName)
environment: 'App Production AKS'
strategy:
runOnce:
deploy:
steps:
- task: PublishPipelineArtifact@1
displayName: Publish k8s manifests
inputs:
targetPath: $(Build.SourcesDirectory)/k8s
artifactName: k8s
artifactType: pipeline
- task: KubernetesManifest@0
displayName: Create imagePullSecret
inputs:
action: createSecret
secretName: $(imagePullSecret)
kubernetesServiceConnection: 'App Production AKS'
dockerRegistryEndpoint: $(dockerRegistryServiceConnection)
- task: KubernetesManifest@0
displayName: Deploy to api Kubernetes cluster
inputs:
action: deploy
kubernetesServiceConnection: 'App Production AKS'
manifests: |
$(Pipeline.Workspace)/k8s/aks/api.yaml
imagePullSecrets: |
$(imagePullSecret)
containers: |
$(containerRegistry)/$(imageRepository)-api:$(tag)我尝试了十几种不同的方法来发布k8s清单,错误消息通常是这样的:
##[error]Path does not exist: /home/vsts/work/1/s/k8s
# or
##[error]No manifest file(s) matching /home/vsts/work/1/k8s/aks/api.yaml was found.如何解决这个问题的建议?
显然,有一些概念我没有完全掌握。
发布于 2021-03-15 05:58:48
好吧,这是否被认为是好的/实践是另一回事,但我确实让它在以下情况下工作:
# deployment.yaml (does not work)
trigger:
branches:
include:
- production
resources:
- repo: self
variables:
- template: templates/variables.yaml
stages:
- stage: Publish
displayName: Publish artifacts
jobs:
- job: Publish
displayName: Publish
pool:
vmImage: $(vmImageName)
steps:
- upload: k8s
artifact: k8s
- stage: Deploy
displayName: Deploy stage
dependsOn: Publish
jobs:
- deployment: Deploy
displayName: Deploy
pool:
vmImage: $(vmImageName)
environment: 'App Production AKS'
strategy:
runOnce:
deploy:
steps:
- task: KubernetesManifest@0
displayName: Create imagePullSecret
inputs:
action: createSecret
secretName: $(imagePullSecret)
kubernetesServiceConnection: 'App Production AKS'
dockerRegistryEndpoint: $(dockerRegistryServiceConnection)
- task: KubernetesManifest@0
displayName: Deploy to api Kubernetes cluster
inputs:
action: deploy
kubernetesServiceConnection: 'App Production AKS'
manifests: |
$(Pipeline.Workspace)/k8s/aks/api.yaml
imagePullSecrets: |
$(imagePullSecret)
containers: |
$(containerRegistry)/$(imageRepository)-api:$(tag)https://stackoverflow.com/questions/66619806
复制相似问题