我可以在Azure Pipelines中对变量进行子字符串化吗? [英] Can I substring a variable in Azure Pipelines?

查看:75
本文介绍了我可以在Azure Pipelines中对变量进行子字符串化吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在我的 azure-pipelines.yml 文件中定义变量的方法,可以在其中对'Build.SourceVersion'->进行子字符串化.仅前7个字符.

I'm looking for a way to define a variable in my azure-pipelines.yml file where I can substring the 'Build.SourceVersion' -> Use the first 7 characters only.

似乎在文档中没有内置函数可以执行此类字符串操作.有什么我想念的吗?

Seems like there is no build-in function that can do such string operations in the documentation. Is there something I'm missing?

我的另一种方法是使用bash任务并在那里覆盖变量,但是找到可以做到这一点的内置方法将是更好的解决方案.

My other approach would be to use a bash task and overwrite the variable there but finding something build-in that can do this would be way better solution.

推荐答案

我的另一种方法是使用bash任务并在那里覆盖变量,但是找到可以做到这一点的内置方法将是更好的解决方案.

My other approach would be to use a bash task and overwrite the variable there but finding something build-in that can do this would be way better solution.

我同意卢卡斯.没有这样的内置任务来获取Azure DevOps中$(Build.SourceVersion)的前7个字符.

I agree with Lucas. There is no such built-in task to get the first 7 characters of $(Build.SourceVersion) in Azure DevOps.

我们可以使用命令行/powershell任务将长阴影分割成短阴影:

We could use the command line/powershell task to split long sha into short sha:

echo $(Build.SourceVersion)

set TestVar=$(Build.SourceVersion)

set MyCustomVar=%TestVar:~0,7%

echo %MyCustomVar%

echo ##vso[task.setvariable variable=ShortSourceVersion]%MyCustomVar%

在这种情况下,我们可以获取 Build.SourceVersion 的简短版本并将其设置为环境变量.

In this case, we could get the short versions of Build.SourceVersion and set it as environment variable.

然后我们可以将此命令行任务设置为任务组:

Then we could set this command line task as a task group:

因此,我们可以使用此任务直接设置 ShortSourceVersion .

So, we could use this task to set the ShortSourceVersion directly.

希望这会有所帮助.

这篇关于我可以在Azure Pipelines中对变量进行子字符串化吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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