[英]Why does powershell env works locally but not with dockerfile?
So I ran this command on my local machine.所以我在本地机器上运行了这个命令。 Scrubbed link for obvious reasons.
出于显而易见的原因删除了链接。
scalar clone --full-clone https://$env:USERNAME:$env:PAT_TOKEN@<MY GIT REPO LINK HERE>
But running this doesn't work in a dockerfile.但是在 dockerfile 中运行它不起作用。 Even with the ARGs passed in during the build.
即使在构建过程中传入了 ARG。 And yes, I've checked them by printing them out.
是的,我已经通过打印出来检查过它们。
RUN scalar clone --full-clone https://$env:USERNAME:$env:PAT_TOKEN@<MY GIT REPO LINK HERE>
But if I just add a back slash in the right place, it works...但是如果我只是在正确的位置添加一个反斜杠,它就可以工作......
RUN scalar clone --full-clone https://$env:USERNAME\:$env:PAT_TOKEN@<MY GIT REPO LINK HERE>
Any ideas?有任何想法吗?
I don't think it works locally, because you appear to have hit a bug (as of PowerShell 7.0) , which can more simply be demonstrated thus:我不认为它在本地工作,因为您似乎遇到了一个错误(从 PowerShell 7.0 开始) ,可以更简单地证明如下:
# Command based on *Windows* environment vars., but the bug affects Unix too.
PS> Write-Output $env:OS:$env:USERNAME@more
jdoe@more # !! only the *2nd* variable value is output.
The bug surfaces when two $env:<name>
references are directly joined with a :
(your insertion of \\
before the :
bypassed the bug).当两个
$env:<name>
引用直接与:
连接时,错误就会$env:<name>
(您在:
之前插入的\\
绕过了错误)。
The workaround is to enclose the variable name (including the env:
namespace prefix) in {...}
, which is PowerShell's mechanism for disambiguating variable names from adjacent characters in (implicit) expandable strings:解决方法是将变量名称(包括
env:
命名空间前缀)括在{...}
,这是 PowerShell 用于从(隐式)可扩展字符串中的相邻字符中消除变量名称歧义的机制:
# Workaround: enclose the variable name in {...}
PS> Write-Output ${env:OS}:$env:USERNAME@more
Windows_NT:jdoe@more # OK.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.