Azure devops管道条件名称 [英] Azure devops pipelines conditional name

查看:135
本文介绍了Azure devops管道条件名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用azure-devops管道,但是在设置版本名称时遇到了问题.

I am using azure-devops pipelines but I am having problems to set the name of the build.

这是一个普通的构建定义.

Here is a normal build definition.

pool:
  vmImage: 'VS2017-Win2016'

name: myBuildName

steps:
- task: NuGetToolInstaller@0

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

我想做的是通过条件检查来设置名称.如果是(某物),那么X否则为Y

What I would like to do is to set the name with a conditional check. If (something) then X otherwise Y

我已经检查了有条件的文件,但没有运气.

I have checked the conditional documents, but no luck.

这是我想做的,但显然不起作用

Here is what I would like to do, but obviously does not work

# if ReleaseNumber var exists
if ($(ReleaseNumber))
  name: $(ReleaseNumber).$(Build.BuildId)
else
  name: $(date:yyyyMMdd)$(rev:.r)

推荐答案

Azure DevOps YAML不支持您尝试执行的值中的条件.

Azure DevOps YAML doesn't support conditions in the values like you tried to do.

您查找的条件文档用于执行作业/任务,您可以指定何时以自定义条件执行任务.

The conditional documents you looked is for jobs/tasks execution, you can specify when the task will be executed with a custom condition.

在解决方法中,您可以添加一个PowerShell任务,该任务将根据您的条件更新构建名称.

At workaround, you can add a PowerShell task that will update the build name according to your condition.

例如,将$(date:yyyyMMdd)$(rev:.r)保留在名称中,并在构建过程中运行以下脚本:

For example, keep the $(date:yyyyMMdd)$(rev:.r) in the name and run this script during the build:

if ($env:ReleaseNumber){
  Write-Host "##vso[build.updatebuildnumber]$env:ReleaseNumber.$env:Build_BuildId"
  }
else{
  Write-Host "Release Number not exist, build name not changed"
  }

这篇关于Azure devops管道条件名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆