12

The Problem

A GitHub trigger set up in Google Cloud Build doesn't actually substitute the configured values while running the Build (cloudbuild.yaml)

This is the Google Cloud Build config

cloudbuild.yaml

steps:
- name: 'gcr.io/cloud-builders/gcloud'
  id: 'decrypt .npmrc'
  args:
  - kms
  - decrypt
  - --ciphertext-file=npmrc.enc
  - --plaintext-file=/root/.npmrc
  - --location=global
  - --keyring=my-keyring
  - --key=npm-key
  - --project=${_CLOUD_KMS_PROJECT}
  volumes:
    - name: 'home'
      path: /root/
- name: 'gcr.io/cloud-builders/npm'
  id: 'install'
  args: ['install']
  env:
  - HOME=/root/
  volumes:
  - name: 'home'
    path: /root/
- name: 'gcr.io/cloud-builders/npm'
  id: 'test'
  args: ['run', 'test']
- name: gcr.io/$PROJECT_ID/skaffold:alpha
  id: 'deploy'
  args: ['run', '-f=${_SKAFFOLD_FILE}']
  env:
  - CLOUDSDK_COMPUTE_ZONE=${_CLOUDSDK_COMPUTE_ZONE}
  - CLOUDSDK_CONTAINER_CLUSTER=${_CLOUDSDK_CONTAINER_CLUSTER}
substitutions:
    _SKAFFOLD_FILE: dummy.yaml
    _CLOUDSDK_COMPUTE_ZONE: us-west1-a
    _CLOUDSDK_CONTAINER_CLUSTER: dummy
timeout: 1000s

Curiously, when triggering the build via a gcloud SDK call it works ✅ ex:

gcloud builds submit --config=cloudbuild.yaml --substitutions=_SKAFFOLD_FILE=skaffold.yaml,_CLOUDSDK_COMPUTE_ZONE=us-west1-a,_CLOUDSDK_CONTAINER_CLUSTER=skaffold .

Some more context

Cloud Build Trigger dashboard (img)

Trigger configuration with substitutions (img)

Missing substitutions in Build history from triggered build (img)

In contrast: Correctly substituted values when running gcloud builds submit (img)

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Joel Baudin
  • 171
  • 1
  • 6
  • could you rephrase this into a question - or add it as possible approach to an answer to your other one question? you can answer your own questions, while it should always be Q & A (in order to keep things together). – Martin Zeitler Sep 20 '18 at 13:29
  • @MartinZeitler Updated the title (rephrased into a question) now. Do you mean I should link this in some way in the other question? – Joel Baudin Sep 20 '18 at 18:12
  • It's unclear what you're seeing. Can you add some errors or screenshots about variables not working? – ahmet alp balkan Sep 21 '18 at 17:14
  • @AhmetAlpBalkan-Google See these screenshots (also linked above) [Missing substitutions in Build history from triggered build (img)](https://i.stack.imgur.com/OOEjX.png), [In contrast: Correctly substituted values when running gcloud builds submit (img)](https://i.stack.imgur.com/GwTzw.png) – Joel Baudin Sep 24 '18 at 08:06
  • [These are the substitutions I expect to see when the build runs (img)](https://i.stack.imgur.com/5mPZS.png) through Cloud Build – Joel Baudin Sep 24 '18 at 08:12
  • 1
    Are you still facing this issue? I tried to reproduce it on my own project, but it worked as expected and I was able to substitute the configured values. – alextru Apr 30 '19 at 13:18
  • I can't see a substitution defined for _CLOUD_KMS_PROJECT. Would that fail when submitted locally? Also, check the indent is correct on the substitution params. I have seen your issue. I resolved it by removing all build errors after locally submitting the file, including removing unused substitution params. – intotecho Jul 03 '20 at 05:43

0 Answers0