我正在寻找为什么DEV环境在测试阶段后没有立即执行的原因。一般规则是我有两个管道:第一个管道仅执行测试,然后触发第二个管道,该管道应在开发环境上使用 Terraform 执行实际部署。第一部分有效,即第一个管道正确触发第二个管道,但触发的管道不会启动开发环境。
管道.yaml
name: MySource
resources:
repositories:
- repository: Library
type: git
name: Library
ref: test/pipeline
trigger:
batch: true
branches:
include:
- test/pipeline
parameters:
- name: pipelineMode
displayName: Pipeline Mode
type: string
default: main
values:
- auto
- feature
- main
- release
# rest of the code goes here
它会触发下面的一个:
dependant_pipeline.yaml
trigger: none
resources:
repositories:
- repository: Library
type: git
name: Library
ref: test/pipeline
pipelines:
- pipeline: test-triggered
project: DEV
source: 'library'
trigger:
branches:
include:
- test/pipeline
parameters:
- name: pipelineMode
displayName: Pipeline Mode
type: string
default: main
values:
- auto
- feature
- main
- release
variables:
- template: /templates/options.yml
stages:
- stage: Testing
displayName: Testing
- template: /templates/build.yml
parameters:
pipelineOptions:
pipelineMode: ${{variables.pipelineMode}}
sourceBranchType: ${{variables['Pipeline.SourceBranchType']}}
normalizedSourceBranch: $(Pipeline.NormalizedSourceBranch)
isDeploymentPlanned: ${{variables.isDeploymentPlanned}}
isDetectChangesEnabled: ${{ne(parameters.detectChangesFolders, '')}}
isIgnoreServicePermissions: ${{parameters.ignoreServicePermissions}}
devEnvironment: ${{parameters.devEnvironment}}
devVariables: ${{parameters.devVariables}}
environmentTemplate: ${{parameters.deployEnvironmentTemplate}}
deployParameters: ${{parameters.deployParameters}}
由另一个管道触发一个管道的部分是有效的,并在 Azure DevOps 上完成了一些额外的步骤。 对我来说,问题始于下面的某个地方。
/模板/build.yml
# ...
stages:
- ${{ if ne(parameters.devEnvironment, '') }}:
- stage: DEV
displayName: DEV Env
dependsOn: Testing
condition: and(succeeded(), eq('${{parameters.pipelineOptions.pipelineMode}}', 'main'))
variables:
- template: ${{parameters.devVariables}}
- name: environment
value: ${{parameters.devEnvironment}}
readonly: true
- name: env
value: dev
readonly: true
pool:
name: $(agentPool)
jobs:
- template: ${{parameters.environmentTemplate}}
parameters:
pipelineOptions: ${{parameters.pipelineOptions}}
environment: ${{variables.environment}}
env: ${{variables.env}}
${{each param in parameters.deployParameters}}:
${{param.key}}: ${{param.value}}
# ...
/模板/选项.yml
parameters:
- name: pipelineMode
type: string
variables:
- name: Pipeline
value:
readonly: true
- name: Pipeline.NormalizedSourceBranch
value: ${{replace(replace(coalesce(variables['System.PullRequest.SourceBranch'], variables['Build.SourceBranch']),'refs/heads/',''),'/','__')}}
readonly: true
- name: Pipeline.SourceBranchType
readonly: true
${{ if eq(variables['Build.SourceBranch'], 'refs/heads/main') }}:
value: "main"
${{ elseif startsWith(variables['Build.SourceBranch'], 'refs/heads/release/') }}:
value: "release"
${{ else }}:
value: "feature"
- name: pipelineMode
readonly: true
${{ if eq(parameters.pipelineMode, 'auto') }}:
value: ${{variables['Pipeline.SourceBranchType']}}
${{ else }}:
value: ${{parameters.pipelineMode}}
出于测试目的,我创建了自己的名为 test/pipeline 的分支,我注意到当我将其添加为管道中的引用时,问题就开始了。所以,原因可能就在这里。以前,管道设置为主,整个工作流程运行没有问题。然而,我需要在自己的分支中执行此操作,这就是为什么在管道中设置 test/pipeline 的原因。
我将代码缩短为我认为导致开发环境无法执行的部分。希望我没有剪掉太多。
经过我的多次尝试,所有这些都导致了开发环境的缺乏。执行。
快速查看您的代码,我发现
dependant_pipeline.yaml
中存在一些问题:
devEnvironment
参数未声明:
devEnvironment: ${{parameters.devEnvironment}}
您忘记将
pipelineMode
参数传递给 /templates/build.yml