GitLab - 写入主机:找不到命令
GitLab - Write-Host: command not found
我有以下 GitLab CI yml 文件:
stages:
- build
CodeQuality:
stage: build
image:
name: "mcr.microsoft.com/powershell:latest"
script:
- Write-Host "Do your build here, z1234."
管道失败并出现此错误:
/usr/bin/bash: line 105: Write-Host: command not found
在另一个 SO 问题中,显示了一条类似的错误消息,一条评论提到 docker 容器没有安装 PowerShell。因此,我添加了 image
属性 但它仍然失败。
我也试过用
- powershell "Write-Host 'Do your build here, z1234.'"
或这个
- powershell -Command "Write-Host 'Do your build here with PAM.'"
但后来我只得到这个错误:
$ powershell -Command "Write-Host 'Do your build here with PAM.'"
/usr/bin/bash: line 110: powershell: command not found
但这也没有识别命令powershell
。
我还缺少什么?
我不知道您的运行器中配置了哪个 shell,但您示例中的命令似乎是在 bash
或 sh
上下文中执行的。
在您使用 Powershell 的映像中,内核 pwsh
可用于执行 Powershell 命令。
此脚本部分有效:
script:
- pwsh -Command "Write-Host "Do your build here, z1234.""
我有以下 GitLab CI yml 文件:
stages:
- build
CodeQuality:
stage: build
image:
name: "mcr.microsoft.com/powershell:latest"
script:
- Write-Host "Do your build here, z1234."
管道失败并出现此错误:
/usr/bin/bash: line 105: Write-Host: command not found
在另一个 SO 问题中,显示了一条类似的错误消息,一条评论提到 docker 容器没有安装 PowerShell。因此,我添加了 image
属性 但它仍然失败。
我也试过用
- powershell "Write-Host 'Do your build here, z1234.'"
或这个
- powershell -Command "Write-Host 'Do your build here with PAM.'"
但后来我只得到这个错误:
$ powershell -Command "Write-Host 'Do your build here with PAM.'"
/usr/bin/bash: line 110: powershell: command not found
但这也没有识别命令powershell
。
我还缺少什么?
我不知道您的运行器中配置了哪个 shell,但您示例中的命令似乎是在 bash
或 sh
上下文中执行的。
在您使用 Powershell 的映像中,内核 pwsh
可用于执行 Powershell 命令。
此脚本部分有效:
script:
- pwsh -Command "Write-Host "Do your build here, z1234.""