在 Azure DevOps 上构建期间,我尝试使用 tox 从私有(private) git 存储库安装包,但出现错误
Collecting git+https://****@<company>.visualstudio.com/<team>/_git/<repo_name>@<branch>
Cloning https://****@<company>.visualstudio.com/<team>/_git/<repo_name> (to revision <branch>) to c:\users\vssadm~1\appdata\local\temp\pip-req-build-xpl77xit
Running command git clone -q 'https://****@<company>.visualstudio.com/<team>/_git/<repo_name>' 'C:\Users\VSSADM~1\AppData\Local\Temp\pip-req-build-xpl77xit'
fatal: Cannot prompt because user interactivity has been disabled.
fatal: could not read Password for 'https://$(System.AccessToken)@<company>.visualstudio.com': terminal prompts disabled
tox.ini 设置为
passenv = *
deps =
git+https://$(System.AccessToken)@<company>.visualstudio.com/<team>/_git/<repo_name>@<branch>
我已确保 Azure DevOps 构建代理用户对
当我创建一个脚本任务来简单地运行pip install git+https://$(System.AccessToken)@<company>.visualstudio.com/<team>/_git/<repo_name>@<branch>
时安装成功。
有没有办法使用 $(System.AccessToken)
有毒吗?
最佳答案
在 tox.ini 中,不要使用 $(System.AccessToken)
使用{env:SYSTEM_ACCESSTOKEN}
.
Azure DevOps 管道允许从其预定义管道变量 System.AccessToken
获取访问 token 或环境变量。管道变量可以在构建定义或任务中使用。
在尝试使用$(System.AccessToken)
的情况下在 tox.ini 中,该构建变量不会被交换,因为 tox 直接读取文件并且仅使用该字符串而不进行任何替换。看起来它正在替换,因为日志显示 Collecting git+https://****@<company>.visualstudio.com
,但这只是 DevOps 看到的 Collecting git+https://$(System.AccessToken)@<company>.visualstudio.com
并在打印到日志之前进行交换。还要注意在最后一个致命日志中它写入 $(System.AccessToken)
fatal: could not read Password for 'https://$(System.AccessToken)@<company>.visualstudio.com': terminal prompts disabled
.
Azure DevOps 使这些管道变量可用作环境变量。对于 System.AccessToken,此环境变量为 SYSTEM_ACCESSTOKEN
。要访问tox中的环境变量,语法为 {env:KEY}
。因此,要通过 tox 访问 System.AccessToken,请使用 {env:SYSTEM_ACCESSTOKEN}
:
passenv = *
deps =
git+https://{env:SYSTEM_ACCESSTOKEN}@<company>.visualstudio.com/<team>/_git/<repo_name>@<branch>
关于python - 使用 $(System.AccessToken) 在 Azure DevOps 构建管道上使用私有(private) git 存储库中的 tox 安装包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68107540/