没有让Docker从Jenkins中运行

我有一个Jenkinspipe道,成功地build立一个docker形象。 但是,当运行docker-image时,它会失败。 在Docker镜像里我有一些APItesting,我想用ctest来运行。 testing可以通过调用目录/ testing中的test来执行。

有什么build议么?

pipeline { agent {label 'apitest-centos7'} stages { stage('cleanup'){ steps{ cleanWs() } } stage('git checkout Dockerfile') { steps{ checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'ebf01b-3gf93-4f8e-9f69-97ffgff308af', url: 'http://gitlab.somecompany.loc/somecompany/MyApiTestingTools.git']]]) sh 'ls' } } stage('build Dockerimage'){ steps{ dir('dockerbuild'){ fileExists 'Dockerfile' sh 'sudo docker build --no-cache=true -t apitestimage .' } } } stage('start Dockerimage and Tests') { steps{ dir("dockerbuild"){ withDockerContainer(args: "-ti apitestimage bash -c 'cd testing && ctest", image: 'apitestimage') { } } } } } post { always { /*mattermostSend color: 'good', message: 'API-Tests have been executed'*/ deleteDir() /* clean up our workspace */ } success { mattermostSend color: 'good', message: 'API-Tests succeded', channel: 'api-tests' } unstable { mattermostSend color: 'warning', message: 'API-Tests are unstable', channel: 'api-tests' } failure { mattermostSend color: 'danger', message: 'API-Tests have failed', channel: 'api-tests', icon: 'http://img.gdocker.com/docker/jenkins.png' } changed { mattermostSend color: 'warning', message: 'API-Tests have changed', channel: 'api-tests' } } } 

我猜想3个错误的原因:

  • 你正在尝试在没有tty的环境(jenkins构build环境)下使用tty( -it options)启动容器交互模式,这可能会导致一些问题
  • 你给图像名称两次:在argsimage
  • 你没有closures报价

试着改变这个:

 withDockerContainer(args: "bash -c 'cd testing && ctest'", image: 'apitestimage') 

顺便说一句,你可以考虑使用dockerpipe道API :

 stage('build Dockerimage') { steps { script { apitestimage = docker.build('apitestimage', '--no-cache=true dockerbuild') } } } stage('start Dockerimage and Tests') { steps{ script { apitestimage.inside { sh 'cd testing && ctest' } } } } 

docker.inside在当前工作空间上挂载一个卷时,甚至可以避免创build映像(您不需要发布它,所以我想这只是testing所必需的),并从基本映像启动必要的命令来构buildtesting环境并启动testing。