本文介绍了依赖工作从上一阶段获得价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行两个阶段的管道.这些阶段基本上是相同的,除了一个阶段依赖于另一个阶段.他们都引用了包含两个作业的模板,一个作业取决于另一个.第一个作业创建一个输出变量,第二个作业使用它.

问题是有两个JobA和两个JobB,而JobB似乎不知道哪个JobA是正确的.这是YAML:

 #azure-pipelines.yaml阶段:-阶段:deployQA职位:-模板:stage-template.yaml参数:环境:质量检查-阶段:deployStagingDependOn:deployQA条件:成功()职位:-模板:stage-template.yaml参数:环境:STAGING 
 #stage-template.yaml参数:环境: ''职位:-工作:preDeploy变量:artifactName:preDeploy-$ {{parameters.environment}}环境:$ {{parameters.environment}}脚步:-结帐:无-发布:$(Pipeline.Workspace)人工制品:$(artifactName)-pwsh:|echo"## vso [task.setvariable variable = artifactName; isOutput = true] $($ env:ARTIFACTNAME)"名称:outputVars-工作:部署DependOn:preDeploy变量:artifactName:$ [dependencies.preDeploy.outputs ['outputVars.artifactName']]脚步:-结帐:无-下载:当前人工制品:$(artifactName) 

问题出在该行第二个文件的底部:

  artifactName:$ [dependencies.preDeploy.outputs ['outputVars.artifactName']] 

运行QA阶段时, $ [dependencies.preDeploy.outputs ['outputVars.artifactName']] 解析为 preDeploy-QA ,并且在暂存阶段为运行,它也解析为 preDeploy-QA .查看日志,我可以看到它们的解析不正确:

 //2_deployment.txt变量:artifactName:解析表达式:< dependencies.preDeploy.outputs ['outputVars.artifactName']>评估:dependency ['preDeploy'] ['outputs'] ['outputVars.artifactName']结果:"preDeploy-QA"//2_deployment(1).txt变量:artifactName:解析表达式:< dependencies.preDeploy.outputs ['outputVars.artifactName']>评估:dependency ['preDeploy'] ['outputs'] ['outputVars.artifactName']结果:"preDeploy-QA"我在这里做错了吗?还是这是一个错误?您可以在[此处] [1]中看到YAML和日志.[1]:https://dev.azure.com/lolinctest/PublicTest/_build/results?buildId = 506& view = results 
解决方案

否,您没有做错任何事情,请参考此问题通知单,该问题通知单最近在我们的开发者社区上进行了报告:

由于从 parameters.environment 中获取值是正确的,因此我们可以在 Download 任务中使用这些脚本来构建工件名称.

在我们的后端,固定代码已提交,PR已完成.只是耐心等待,我们将在最近部署这些固定的.您还可以跟踪门票在开发者社区中进行了报道.部署完成后,我们的团队工程师将在第一时间通知它.

I have a pipeline that runs two stages. The stages are essentially identical, except one depends on the other. They both reference a template that contains two jobs, one job depending on the other. The first job creates an output variable and the second job consumes it.

The problem is that there are two JobA's and two JobB's and JobB doesn't seem to know which JobA is the correct one. Here's the YAML:

# azure-pipelines.yaml
stages:
  - stage: deployQA
    jobs:
    - template: stage-template.yaml
      parameters:
        environment: QA
  - stage: deployStaging
    dependsOn: deployQA
    condition: succeeded()
    jobs:
    - template: stage-template.yaml
      parameters:
        environment: STAGING
# stage-template.yaml
parameters:
  environment: ''
jobs:
- job: preDeploy
  variables:
    artifactName: preDeploy-${{ parameters.environment }}
    environment: ${{ parameters.environment }}
  steps:
  - checkout: none
  - publish: $(Pipeline.Workspace)
    artifact: $(artifactName)
  - pwsh: |
      echo "##vso[task.setvariable variable=artifactName;isOutput=true]$($env:ARTIFACTNAME)"
    name: outputVars
- job: deployment
  dependsOn: preDeploy
  variables:
    artifactName: $[dependencies.preDeploy.outputs['outputVars.artifactName']]
  steps:
  - checkout: none
  - download: current
    artifact: $(artifactName)

The problem is toward the bottom of the second file on this line:

artifactName: $[dependencies.preDeploy.outputs['outputVars.artifactName']]

When the QA stage is run, $[dependencies.preDeploy.outputs['outputVars.artifactName']] resolves to preDeploy-QA and when the Staging stage is run, it also resolves to preDeploy-QA. Looking at the logs, I can see them being resolved incorrectly:

// 2_deployment.txt
Variables:
  artifactName:
    Parsing expression: <dependencies.preDeploy.outputs['outputVars.artifactName']>
    Evaluating: dependencies['preDeploy']['outputs']['outputVars.artifactName']
    Result: 'preDeploy-QA'

// 2_deployment (1).txt
Variables:
  artifactName:
    Parsing expression: <dependencies.preDeploy.outputs['outputVars.artifactName']>
    Evaluating: dependencies['preDeploy']['outputs']['outputVars.artifactName']
    Result: 'preDeploy-QA'

I am doing something wrong here? Or is this a bug?

You can see the YAML and logs [here][1].

  [1]: https://dev.azure.com/lolinctest/PublicTest/_build/results?buildId=506&view=results
解决方案

No, you did not do any thing wrong, refer to this issue ticket which report on our Developer Community recently: Setting output variable when multiple stages share a job results in unexpected sharing. Just while the multi stage share the the same job(template), the value will be confusing.

This is the issue that the Product Group has identified it as caused by our side. We have finished the investigate, the fixed script is pending release now.

But, for not to affect the normal build, there has a workaround, we can avoid to use this issue variable expression.

Just reconstruct the artifact name with another method:

  - download: current
    artifact: preDeploy-${{ parameters.environment }}

Since it's correct to get the value from parameters.environment, so we can construct the artifact name with these script in the Download task.

On our backend, the fixed code has been committed and PR is finished. Just patience for waiting, we will deploy these fixed recently. You can also track that ticket which reported in Developer Community. Once it deployed, our team engineer will inform it there at first time.

这篇关于依赖工作从上一阶段获得价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 16:40