将输出变量传递到 Azure DevOps 中同一作业中的模板

问题描述 投票:0回答:1

我正在尝试将由步骤组成的模板中输出的变量传递到同一作业中的另一个步骤模板,设置如下所示,

错误:

semVersion 参数值不是有效值

jobs:
     - job: job_git_tag
       displayName: Tag new version

       steps:
         - template: /templates/git/semantic_version_type.yaml
           parameters:
             semVersion: ${{ parameters.semVersion }}
         
         - template: /templates/git/git_tag.yaml
           parameters:
             module: ${{ parameters.module }}
             semVersion: $(Type.Semversion)

模板语义版本

parameters:
  - name: semVersion
    type: string
    default: auto
    values:
      - major
      - minor
      - patch
      - auto

steps:
  - ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
    - bash: |
           ### do some scripting magic and output variable
           echo "##vso[task.setvariable variable=semVersion;isOutput=true]major"
    displayName: Get semantic version type
    name: Type

Git 标签模板

parameters:
  - name: module
    type: string
  - name: semVersion
    type: string
    default: patch
    values:
      - major
      - minor
      - patch

steps:

  - bash: |
      ### here the repository is checkedout and tagged with the correction version after being bumped.
    displayName: Tag new version
azure-devops yaml azure-pipelines cicd azure-pipelines-yaml
1个回答
0
投票

parameters
compile time
在管道运行之前进行评估,支持将第一个模板中的变量值作为第二个模板的参数传递。

作为替代方案,您可以删除第二个模板的

semVersion: $(Type.Semversion)
,直接在模板中调用它。

jobs:
- job: job_git_tag
  displayName: Tag new version

  steps:
    - template: /templates/git/semantic_version_type.yaml
      parameters:
        semVersion: ${{ parameters.semVersion }}
    
    - template: /templates/git/git_tag.yaml
      parameters:
        module: ${{ parameters.module }}

第二个模板:

parameters:
  - name: module
    type: string
  # - name: semVersion
  #   type: string
  #   default: patch
  #   values:
  #     - major
  #     - minor
  #     - patch

steps:

  - bash: |
      echo $(Type.Semversion)
    displayName: Tag new version

我这边输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.