jenkins - 将Docker镜像推送到Jenkinsfile中的注册表时出错

标签 jenkins docker groovy jenkins-pipeline

我正在使用Jenkinsfile尝试将Docker镜像推送到Jenkins构建管道插件中的本地Docker注册表中。通过阅读文档,我了解到您应该能够推送带有可选标记名的图像:
Image.push([tagname])
我现在有以下代码

  stage('Initialise environment') {
   checkout scm
   db = docker.build('oracle', 'docker/oracle').run("-p 49160:22 -p 49161:1521")
   wlp = docker.build('liberty', 'docker/liberty').run("-p 9080:9080 --link=${db.id}:oracle")
  }
  stage('Push image to registry') {
      docker.withRegistry('https://localhost:5000') {
          db.push()
          wlp.push()
      }
     }

它在第一个push()失败,并显示以下错误:

Failure: groovy.lang.MissingMethodException: No signature of method: static org.jenkinsci.plugins.docker.workflow.Docker.push() is applicable for argument types: () values: [] Possible solutions: use([Ljava.lang.Object;), use(java.util.List, groovy.lang.Closure), use(java.lang.Class, groovy.lang.Closure), dump(), is(java.lang.Object), each(groovy.lang.Closure)



有任何想法吗?

最佳答案

好的,我进行了以下更改,它似乎已解决了该问题:

   dbImage = docker.build('oracle', 'docker/oracle')
   db = dbImage.run("-p 49160:22 -p 49161:1521")
   wlpImage = docker.build('liberty', 'docker/liberty')
   wlp = wlpImage.run("-p 9080:9080 --link=${db.id}:oracle")
  }
  stage('Push image to registry') {
      docker.withRegistry('https://localhost:5000') {
          dbImage.push()
          wlpImage.push()
      }
     }

再次阅读文档,我现在可以看到run()返回了正在运行的容器的句柄,而push()只能在从build()返回的图像对象上调用

关于jenkins - 将Docker镜像推送到Jenkinsfile中的注册表时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41690495/

相关文章:

linux - 无法通过 jenkins 打开 Chrome 浏览器 --- 未知错误 : Chrome failed to start: crashed

java - Jenkins 管道异常 java.io.NotSerializedException : hudson. model.User

amazon-web-services - 具有 CloudFormation 的 AWS SSM 参数存储

groovy - Groovy Abstract ConcurrentMap 中的错误?

groovy - 如何获取 groovy 对象或类的所有变量?

java - 如何在 Java/Groovy 中获得最长连续日和平均日?

junit - 如何在 Junit 测试的 Jenkins 控制台输出中放置粗体文本和格式?

python - Docker Compose Up 给出 "The system cannot find the file specified."错误

ubuntu - 如果使用 jenkins 在作业的 shell 命令上设置,则 docker-compose 无法正常运行

selenium - 在 Docker 容器中执行 Firefox 浏览器进行 Selenium 测试