引用变量天蓝色管道不工作

问题描述 投票:0回答:1

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 azure cicd
1个回答
0
投票

您可以将管道变量的值传递给 Bash 变量,如下所示。

请参阅以下示例作为参考:

variables:
  version: 1

steps:
- bash: |
    echo "version is: $(version)"
    newVersion=$(version).2.3
    echo "newVersion is: $newVersion"
  displayName: 'Set variable'

enter image description here

注意:

上面的 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'

enter image description here


© www.soinside.com 2019 - 2024. All rights reserved.