云构建Docker-价值替代fom jenkins步骤

云构建Docker-价值替代fom jenkins步骤,jenkins,google-cloud-platform,google-cloud-build,Jenkins,Google Cloud Platform,Google Cloud Build,我们正在尝试使用jenkins和cloud build为docker image构建管道。Jenkins将从bit bucket中检出源代码,进行soanrqube代码分析,使用maven构建ArtiaFCT,并推送到nexus artifactory。一旦所有这些步骤都成功完成,下一步就是触发google cloud build,google cloud build将通过从nexus artifactory下载工件来构建docker映像,并将映像推送到GCR 我们面临一个挑战。在maven构建

我们正在尝试使用jenkins和cloud build为docker image构建管道。Jenkins将从bit bucket中检出源代码,进行soanrqube代码分析,使用maven构建ArtiaFCT,并推送到nexus artifactory。一旦所有这些步骤都成功完成,下一步就是触发google cloud build,google cloud build将通过从nexus artifactory下载工件来构建docker映像,并将映像推送到GCR

我们面临一个挑战。在maven构建步骤中,我们将工件的版本从pom.xml存储到一个变量(比如版本)。已将相同的值作为值替换传递给cloud build。但该值并没有从maven构建步骤传递到云构建步骤。下面是云构建代码

- steps: 
  - name: gcr.io/cloud-builders/gsutil 
    args: ['cp', 'gs://test-docker-sai/Dockerfile.txt', 'Dockerfile'] 
  - name: 'gcr.io/cloud-builders/docker' 
    args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/test-image:$_TAG', '.' ] 
  substitutions:
      _TAG=$VERSION
  images: - 'gcr.io/$PROJECT_ID/test-image:$_TAG'
下面是云构建的错误

Step #1: invalid argument "gcr.io/abcd-ef-ghi/test-image:$VERSION" for "-t, --tag" flag: invalid reference format

如何触发cloud build?您希望将Jenkins中的版本环境变量传递给cloud build。一个选项是将环境变量值写入cloud build配置文件,然后让cloud build使用Jenkins编写的配置文件中的环境变量。要在云构建中定义环境变量,您可以冷藏。