2017-01-31 73 views
0

我試圖運行使用Linux外殼和碼頭工人VSTS以下嵌套的命令,這樣我就可以停止並刪除所有都是基於「jspsample」圖像上的容器:命令嵌套

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

enter image description here

不幸的是,代理始終返回下面的錯誤代碼:

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 

有沒有一種方法來運行這個命令的嵌套,或者我需要運行一個SHEL l腳本?

+0

如果您手動在生成代理機器上運行嵌套命令,結果如何? –

回答

1

「命令行」任務不支持命令嵌套。將命令保存爲shell腳本並上傳到代碼庫,然後使用「Shell腳本」任務運行該腳本。

1

當我試圖清理每晚構建的圖像時,遇到了同樣的問題。基本上,這個命令:

docker rmi $(docker images -aq) 

所以我創建了泊塢VSTS任務拉請求包括一個輸出變量泊塢窗命令的輸出存儲: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