gpt4 book ai didi

azure - 需要替换 azure devops 管道中预定义变量的别名值

转载 作者:行者123 更新时间:2023-12-03 02:29:55 24 4
gpt4 key购买 nike

我已在两个管道之间启用管道资源触发器。希望通过触发管道资源动态替换别名值。下面是管道代码

  resources:        
pipelines:
- pipeline: pipeline1
project: onecom
source: pipeline1-api
trigger:
branches:
- develop
- feat/*
- pipeline: pipeline2
project: onecom
source: pipeline2-api
trigger:
branches:
- develop
- feat
variables:
- name: apiname
value: $(resources.pipeline.<Alias>.pipelineName)
- name: dockertag
value: $(resources.pipeline.<Alias>.sourceCommit)
- name: runname
value: $(resources.pipeline.<Alias>.runName)

stages:
- stage: ScanImage

jobs:
- job: ScanImage

pool:
vmImage: 'ubuntu-16.04'

steps:
- script: echo $(apiname)
- script: echo $(runname)

如果构建来自 ,我想将 $(resources.pipeline..pipelineName) 中的 Alias 值替换为值 pipeline1>来源:pipeline1-api,如果构建来自动态来源:pipeline2-api,则使用pipeline2

最佳答案

I would like to replace Alias value in $(resources.pipeline..pipelineName) with value pipeline1 if build comes from source: pipeline1-api and with pipeline2 if build comes from source: pipeline2-api dynamically.

由于构建/发布管道尚不支持嵌套变量的值(如$(resources.pipeline.$(alias).pipelineName)))。因此我们无法直接在变量中使用它:

  variables:
- name: apiname
value: $(resources.pipeline.$(alias).pipelineName)

要解决此问题,我们需要添加内联 powershell 来设置变量 resources.pipeline.<Alias>.pipelineName基于 $(resources.triggeringAlias) 的值:

variables:
- name: alias
value: $(resources.triggeringAlias)


- task: InlinePowershell@1
inputs:
script: |
if ("$(alias)" -eq "PipelineA")
{
Write-Host ("##vso[task.setvariable variable=dockertag]$(resources.pipeline.PipelineA.sourceCommit) | cut -c -7")
}
elseif ("$(alias)" -eq "PipelineB")
{
Write-Host ("##vso[task.setvariable variable=dockertag]$(resources.pipeline.PipelineB.sourceCommit) | cut -c -7")
}

更新:

could you please help me same config in bash as we are using thesetask in linux machines

- task: PowerShell@2
displayName: 'Inline Powershell'
inputs:
TargetType: inline
Script: |
if ("$(alias)" -eq "PipelineA")
{
Write-Host ("##vso[task.setvariable variable=dockertag]$(resources.pipeline.PipelineA.sourceCommit) | cut -c -7")
}
elseif ("$(alias)" -eq "PipelineB")
{
Write-Host ("##vso[task.setvariable variable=dockertag]$(resources.pipeline.PipelineB.sourceCommit) | cut -c -7")
}
pwsh: true

关于azure - 需要替换 azure devops 管道中预定义变量的别名值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65598404/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com