Jenkinspipe道用Docker,Google Registry和Google Auth Plugin构build

我正在使用Jenkinspipe道(使用由JHipster自动生成的pipe道脚本)构buildDocker镜像。 我想将我的最终docker图像推送到Google容器registry。

以下是我所做的:

  1. 我已经安装了CloudBees Docker自定义生成环境插件和Google Container Registry Auth插件。
  2. 我在Jenkins按照这里的说明设置了Google auth凭据
  3. 我configuration了我的构build步骤来使用Googleregistry标记格式,如下所示: docker.build('us.gcr.io/[my-project-id]/[my-artifact-id]', 'target/docker')
  4. 我在推送步骤中引用了我的Google身份validation凭据的ID:

(Hm。需要额外的文本行后,项目符号格式正确)

 docker.withRegistry('https://us.gcr.io', '[my-credential-id]') { dockerImage.push 'latest' } 

但是构build失败:

 ERROR: Could not find credentials matching [my-credential-id] Finished: FAILURE 

我基本上认为这些插件在stream水线世界中不起作用,但我想我会问是否有人已经完成了这一点,可以给我一些指示。

尝试用“gcr:”前缀您的凭据ID。

您的凭证ID将看起来像“gcr:[my-credential-id]”。

完整的工作示例:

 stage('Build image') { app = docker.build("[id-of-your-project-as-in-google-url]/[name-of-the-artifact]") } stage('Push image') { docker.withRegistry('https://eu.gcr.io', 'gcr:[credentials-id]') { app.push("${env.BUILD_NUMBER}") app.push("latest") } } 

请注意图像的名称。 我一直在努力推动图像,即使有工作证书,直到我已经命名的形象[id-of-your-project-as-in-google-url] / [名称的神器]符号。

当您收到一条消息,指出您需要启用Google ……. API时,可能是您的[id-of-your-project-as-in-google-url]错误。

现在可以成功使用图像的URL为eu.gcr.io/[id-of-your-project-as-in-google-url]/[name-of-the-artifact]:47。

LZ

我最终通过使用gcloud脚本阶段代替dockerpipe道阶段绕过了这个问题,如下所示:

 stage('publish gcloud') { sh "gcloud docker -- push us.gcr.io/[my-project-id]/[my-artifact-id]" } 

gcloud命令能够在Jenkins服务器的命令行上find使用gcloud init设置的auth凭证。