bash - 如何使用 Bash 在 Azure DevOps 中设置构建变量?
问题描述
我正在使用以下内容从我的 package.json 文件中提取版本并将其设置为我的构建变量之一,Version
.
# successfully retrieves and prints the version to console
ver=$(node -e "console.log(require('./package.json').version)")
echo "Version: $ver"
# does jack squat
# even trying to hard-code something in place of $ver doesn't set the variable
echo "##vso[task.setvariable variable=Version]$ver"
echo "Version: $(Version)"
我尝试使用ver
and$(ver)
而不是$ver
, none 工作,因为控制台$(Version)
在所有情况下都打印空白(一开始是空的)。如果我硬编码Version
,它打印得很好,所以不是打印或检索,而是设置问题。我的脚本基于 MS 的示例,
echo "##vso[task.setvariable variable=sauce]crushed tomatoes"
我们的构建服务器在 Windows 环境中。
解决方案
发布后不久就来了,但我想我会分享以防万一其他人偶然发现这一点。
从文档中,管道变量直到任务结束后才会扩展。微软增强了他们的文档以更好地说明它
steps:
# Create a variable
- script: |
echo '##vso[task.setvariable variable=sauce]crushed tomatoes'
# Use the variable
# "$(sauce)" is replaced by the contents of the `sauce` variable by Azure Pipelines
# before handing the body of the script to the shell.
- script: |
echo my pipeline variable is $(sauce)
我怀疑这就是为什么即使对值进行硬编码,您仍然看不到任何东西。
推荐阅读
- php - PHP:不能在数组中使用空数组元素
- jsf - 如何在数据更改时刷新 ViewScoped(Omnifaces) 页面?
- java - 如何将休眠中的查询结果显示到引导程序中的表?
- linux - OIFS=$IFS是什么意思;IFS="|"; 在 bash 脚本中
- .net - 上下文等待随机失败/连续两次调用相同的“等待方法”
- javascript - 如何使用 Jquery 设置 Html 元素中的变量值?
- python - Python烧瓶服务器需要很长时间才能启动
- tfs - TFS 和 Mantis 的集成
- elasticsearch - 我们可以将一个查询的结果用作弹性搜索中另一个查询的输入吗?
- swift - Swift:addSubview 放在前一个视图上