如何在azure pipeline中使用模板在阶段之间传递变量

0tdrvxhp  于 2023-01-21  发布在  其他
关注(0)|答案(1)|浏览(163)

我试图通过变量与作业之间的阶段是使用模板在蔚蓝色管道,尝试了很多方法,但仍然没有设法实现它。
我的工作是检查一些东西,并创建vso task.variable,这些变量我要传递到下一阶段

蓝色管道.yaml

stages:

  - stage: CheckProjectType
    displayName: Check Project Type
    jobs:            
      - template: jobs/checkprojectype.yaml@devops

  - stage: PrintProjectType
    dependsOn: CheckProjectType
    displayName: Print Project Type
    jobs: 
      - template: jobs/buildproject.yaml@devops
        parameters:
          outputval: $[ stagedependencies.CheckProjectType.outputs['SetValueStep.projecttype'] ]

检查项目类型.yaml

jobs:
- job: CheckProjectType
  displayName: Check Project Type
  steps:
  - bash: |
      if [ -f *.xml ]; then
        echo "JAVA"
      elif [ -f *.json ]; then
        echo "json file found , Nodejs Project Will Be Built"
        echo "##vso[task.setvariable variable=projecttype;]nodejs"
      elif [ -f *.py ]; then
        echo "Python"
      else
        echo "Not Found"
      fi
    name: itay
    displayName: Checking Current Location

生成项目.yaml

jobs:
- job: BuildProject
  variables:
  - name: myvar123
    value: ${{ parameters.outputval }}
  steps:
  - bash: echo $(myvar123)

我希望得到nodejs,但是我什么也没得到,echo是空的

yhived7q

yhived7q1#

如果您想在将来的阶段中共享一个 *task变量 *,它需要一个额外的isOutput=true属性,如本文文档中所述

检查项目类型.yml

jobs:
- job: CheckProjectType
  displayName: Check Project Type
  steps:
  - bash: |
      if [ -f *.xml ]; then
        echo "JAVA"
      elif [ -f *.json ]; then
        echo "json file found , Nodejs Project Will Be Built"
        echo "##vso[task.setvariable variable=projecttype;isOutput=true]nodejs"
      elif [ -f *.py ]; then
        echo "Python"
      else
        echo "Not Found"
      fi
    name: itay
    displayName: Checking Current Location

还要仔细检查@tom-w remark和,因为您的代码示例似乎不适合那里的引用。
在本例中:

outputval: $[ stagedependencies.CheckProjectType.outputs['SetValueStep.projecttype'] ]

应为:

outputval: $[ stagedependencies.CheckProjectType.CheckProjectType.outputs['itay.projecttype'] ]

相关问题