0

We are trying to build pipeline for docker image using jenkins and cloud build. Jenkins will checkout source code from bit bucket, does soanrqube code analysis, builds artiafcts using maven and pushes to nexus artifactory. Once all these steps are completed successfully next step is to trigger google cloud build which will build the docker image by downloading the artifact from nexus artifactory and pushes the image to GCR.

We have a challenge here. In the maven build step we aare storing the version of the artifact from pom.xml to a variable say VERSION. The same value has be passed to cloud build as value substitution. But the value is not passed from maven build step to cloud build step. Below is cloud build code

- 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'

Below is the error from cloud build

Step #1: invalid argument "gcr.io/abcd-ef-ghi/test-image:$VERSION" for "-t, --tag" flag: invalid reference format
Shashikumar KL
  • 1,007
  • 1
  • 10
  • 25
nikhil
  • 21
  • 1
  • how you are triggering cloud build? – Shashikumar KL Mar 09 '20 at 10:05
  • You would like to pass the VERSION environment variable found in Jenkins to Cloud Build. An option to do it, would be to write the environment variable value into a cloud build config file [using Jenkins](https://stackoverflow.com/questions/40992020/write-to-file-with-jenkins-and-groovy) and then let Cloud Build use the environmental variable found in the config file wrote by Jenkins. To define environmental variables in Cloud Build you can reefer [here](https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values#using_user-defined_substitutions). – Christopher Rodriguez Conde Mar 09 '20 at 10:58

0 Answers0