【问题标题】:Command nesting in VSTS/TFSVSTS/TFS 中的命令嵌套
【发布时间】:2017-01-31 12:13:28
【问题描述】:

我正在尝试使用 linux shell 和 Docker 在 VSTS 上运行以下嵌套命令,因此我可以停止并删除所有基于“jspsample”映像的容器:

docker rm $(docker stop $(docker ps -a -q --filter ancestor=jspsample --format="{{.ID}}"))

不幸的是,代理总是返回以下错误代码:

2017-01-31T12:06:22.0585100Z unknown shorthand flag: 'a' in -a

2017-01-31T12:06:22.0636870Z See 'docker stop --help'.

2017-01-31T12:06:22.0827520Z ##[error]/usr/bin/docker failed with return code: 125

2017-01-31T12:06:22.0850140Z ##[error]/usr/bin/docker failed with error: /usr/bin/docker failed with return code: 125

有没有办法运行这个嵌套命令,还是我需要运行一个 shell 脚本?

【问题讨论】:

  • 如果您在构建代理机器上手动运行该嵌套命令会产生什么结果?

标签: docker tfs azure-devops


【解决方案1】:

“命令行”任务不支持命令嵌套。将您的命令保存为 shell 脚本并上传到代码库,然后使用“shell 脚本”任务运行脚本。

【讨论】:

    【解决方案2】:

    当我尝试在夜间构建中清理图像时遇到了同样的问题。基本上这个命令:

    docker rmi $(docker images -aq)
    

    所以我为 Docker VSTS 任务创建了一个拉取请求,以包含一个输出变量来存储 Docker 命令的输出:https://github.com/Microsoft/vsts-docker/pull/44

    有关我对此问题的调查的更多详细信息,请参阅我的 StackOverflow 帖子:Removing unused docker images on a remote Linux Azure hosted docker instance gives 'unknown shorthand flag: 'a' in -aq' error

    【讨论】:

      猜你喜欢
      • 2014-04-05
      • 1970-01-01
      • 2017-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多