管道资源变量上的替换函数
replace function on Pipeline resource variables
按照azure online document and Pipeline resource variables我想从另一个管道获取分支名称,并使用函数replace()
获取真正的分支名称。
variables:
- name: branchName
value: $[replace(variables[resources.pipeline.mypipeline.sourceBranch], 'refs/heads/', '')]
但总是无法通过流水线语法检查
我测试了以下代码,它可以正常工作。
确保将变量用单引号引起来,例如:variables[`resources.pipeline.mypipeline.sourceBranch`]
并且您已经定义了一个指向您的管道的 resources:
块。
pool: default
resources:
pipelines:
- pipeline: james
source: james
variables:
- name: branchName
value: $[replace(variables['resources.pipeline.james.sourceBranch'], 'ref', 'YEAHBUDDY')]
stages:
- stage: approval_check
jobs:
- job: bash
steps:
- task: Bash@3
inputs:
targetType: 'inline'
script: |
# Write your commands here
set -x
echo $(branchName)
Bash 输出:
echo YEAHBUDDYs/heads/main
按照azure online document and Pipeline resource variables我想从另一个管道获取分支名称,并使用函数replace()
获取真正的分支名称。
variables:
- name: branchName
value: $[replace(variables[resources.pipeline.mypipeline.sourceBranch], 'refs/heads/', '')]
但总是无法通过流水线语法检查
我测试了以下代码,它可以正常工作。
确保将变量用单引号引起来,例如:variables[`resources.pipeline.mypipeline.sourceBranch`]
并且您已经定义了一个指向您的管道的 resources:
块。
pool: default
resources:
pipelines:
- pipeline: james
source: james
variables:
- name: branchName
value: $[replace(variables['resources.pipeline.james.sourceBranch'], 'ref', 'YEAHBUDDY')]
stages:
- stage: approval_check
jobs:
- job: bash
steps:
- task: Bash@3
inputs:
targetType: 'inline'
script: |
# Write your commands here
set -x
echo $(branchName)
Bash 输出:
echo YEAHBUDDYs/heads/main