azure-pipelines.yml
variables:
version : "1"
- script: |
echo "version is: ${{variables.version}}" // version is 1
set /a newVersion = $(version) // not working returns empty
newVersion = $(( ${{version}} )) // not working returns empty
bash 脚本不起作用,我想在变量 newVersion 中分配版本并增加数字。有什么帮助吗
您可以将管道变量的值传递给 Bash 变量,如下所示。
请参阅以下示例作为参考:
variables:
version: 1
steps:
- bash: |
echo "version is: $(version)"
newVersion=$(version).2.3
echo "newVersion is: $newVersion"
displayName: 'Set variable'
上面的 Bash 变量
newVersion
仅适用于当前脚本步骤 (Set variable
),不适用于后续步骤。
如果您想在后续脚本步骤中使用
newVersion
的值,可以使用日志记录命令“SetVariable
”来设置管道变量及其值。
echo "##vso[task.setvariable variable=New_Version;]$newVersion"
此命令还将自动为管道变量 (
NEW_VERSION
) 映射环境变量 (New_Version
)。
然后在同一作业的后续步骤中,您可以使用表达式“
$(New_Version)
”直接引用管道变量,或使用表达式$NEW_VERSION
引用其环境变量。
variables:
version: 1
steps:
- bash: |
echo "version is: $(version)"
newVersion=$(version).2.3
echo "newVersion is: $newVersion"
echo "##vso[task.setvariable variable=New_Version;]$newVersion"
displayName: 'Set variable'
- bash: |
echo "version is: $(version)"
echo "newVersion is: $(New_Version)"
echo "newVersion is: $NEW_VERSION"
displayName: 'Print variable'