【发布时间】:2018-03-15 19:08:01
【问题描述】:
我正在尝试检查我的 PowerShell 脚本中的环境变量是否为空或未设置。该脚本在 Docker 容器中运行,如果定义了环境变量,则旨在提取新代码:
CMD if (-not ([string]::IsNullOrEmpty(env:UPDATE_FROM_GITHUB))) { \
Write-Host Git pull started; \
PortableGit\bin\git.exe pull; \
}; \
我收到一堆错误:
web_1 | At line:1 char:110
web_1 | + ... ence = 'SilentlyContinue'; if (-not ([string]::IsNullOrEmpty(env:UPDA ...
web_1 | + ~
web_1 | Missing ')' in method call.
web_1 | At line:1 char:110
web_1 | + ... ue'; if (-not ([string]::IsNullOrEmpty(env:UPDATE_FROM_GITHUB))) { Wr ...
web_1 | + ~~~~~~~~~~~~~~~~~~~~~~
web_1 | Unexpected token 'env:UPDATE_FROM_GITHUB' in expression or statement.
web_1 | At line:1 char:110
web_1 | + ... ence = 'SilentlyContinue'; if (-not ([string]::IsNullOrEmpty(env:UPDA ...
web_1 | + ~
web_1 | Missing closing ')' in expression.
web_1 | At line:1 char:110
web_1 | + ... ue'; if (-not ([string]::IsNullOrEmpty(env:UPDATE_FROM_GITHUB))) { Wr ...
web_1 | + ~~~~~~~~~~~~~~~~~~~~~~
web_1 | Missing closing ')' after expression in 'if' statement.
web_1 | At line:1 char:132
web_1 | + ... e'; if (-not ([string]::IsNullOrEmpty(env:UPDATE_FROM_GITHUB))) { Wri ...
web_1 | + ~
web_1 | Unexpected token ')' in expression or statement.
web_1 | At line:1 char:133
web_1 | + ... '; if (-not ([string]::IsNullOrEmpty(env:UPDATE_FROM_GITHUB))) { Writ ...
web_1 | + ~
web_1 | Unexpected token ')' in expression or statement.
web_1 | At line:1 char:134
web_1 | + ... ; if (-not ([string]::IsNullOrEmpty(env:UPDATE_FROM_GITHUB))) { Write ...
我不知道如何从这里开始。这些错误似乎是多余的,但没有明确的起点。会不会跟 Docker 解析命令的方式有关系?
【问题讨论】:
标签: powershell docker environment-variables