groovy 将$()与sh或/bin/bash一起使用时出现Jenkinsfile错误

n53p2ov0  于 2022-11-01  发布在  Jenkins
关注(0)|答案(1)|浏览(140)

我在Jenkinsfile中有一个步骤,看起来像这样:

steps {
        sh '''#!/bin/bash
              docker kill $(docker ps -q --filter ancestor=nginx-example )'''
        sh '''docker build -t nginx-example .
              docker run -d -p 8081:80 nginx-example'''
      }

而像这样的错误

"docker kill" requires at least 1 argument.
See 'docker kill --help'.

Usage:  docker kill [OPTIONS] CONTAINER [CONTAINER...]

Kill one or more running containers
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

我怎么能用$()运行docker kill呢?它只在Jenkinsfile中不起作用,而在Jenkins Pipeline中它完全工作正常。

elcex8rz

elcex8rz1#

是否有一个名为nginx-example的docker正在运行?如果docker没有运行,那么我在bash中也会得到同样的错误:


# docker kill $(docker ps -q --filter ancestor=nginx-example )

"docker kill" requires at least 1 argument.
See 'docker kill --help'.

Usage:  docker kill [OPTIONS] CONTAINER [CONTAINER...]

Kill one or more running containers

如果它处于停止状态,建议使用docker ps -a

相关问题