gpt4 book ai didi

Azure DevOps 管道无法识别 Bash 脚本中的管道变量(不使用 YAML 文件)

转载 作者:行者123 更新时间:2023-12-02 23:37:14 25 4
gpt4 key购买 nike

Azure DevOps 管道具有以下变量:

  • 姓名:pat
  • 值:Git 存储库身份验证 token

管道有一个 Bash 脚本任务。它被设置为文件路径。文件路径设置为 script.sh。 script.sh 开头为:

git clone https://username:$(PAT)@dev.azure.com/company/project/_git/repo-name

管道日志中的错误:

PAT: command not found
Cloning into 'repo-name'...
fatal: Authentication failed for 'https://dev.azure.com/healthcatalyst/CAP/_git/docs-template/'

为了验证身份验证 token 和存储库 URL 是否准确,我可以验证它在作为内联代码运行时是否有效:

git clone https://username:$(pat)@dev.azure.com/company/project/_git/repo-name

script.sh 文件位于 repo-name 中。

但是,环境变量可以发挥作用。以下两者都返回脚本中的准确值。请注意,一个没有引号,另一个有。

echo $BUILD_REPOSITORY_NAME
repo-name

echo "$BUILD_REPOSITORY_NAME"
repo-name

根据我看到的文档(我在使用 Microsoft 文档时遇到困难,因为我没有使用 YAML 文件),我尝试过但没有成功:

  • $pat
  • $PAT
  • $(PAT)
  • "$(PAT)"
  • gitToken=<backtick - Markdown is not allowing me to show a backtick here>echo $PAT<backtick>

有人知道我做错了什么吗?感谢您提供任何提示。

最佳答案

您的 PAT 变量是 secret 变量吗?

如果是这样,则无法在脚本文件中直接访问它

正如您在文档中看到的:https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#secret-variables

Unlike a normal variable, they are not automatically decrypted into environment variables for scripts. You need to explicitly map secret variables.

示例:

...  
env:
MY_MAPPED_ENV_VAR: $(mySecret) # the recommended way to map to an env variable

或者,如果您使用可视化编辑器,如下所示: enter image description here

关于Azure DevOps 管道无法识别 Bash 脚本中的管道变量(不使用 YAML 文件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69561203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com