How do I get Google Cloud Build to properly substitute values when it responds to a GitHub trigger?
Asked Answered
D

0

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)

Determinism answered 20/9, 2018 at 10:53 Comment(7)
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).Casseycassi
@MartinZeitler Updated the title (rephrased into a question) now. Do you mean I should link this in some way in the other question?Determinism
It's unclear what you're seeing. Can you add some errors or screenshots about variables not working?Fuscous
@AhmetAlpBalkan-Google See these screenshots (also linked above) Missing substitutions in Build history from triggered build (img), In contrast: Correctly substituted values when running gcloud builds submit (img)Determinism
These are the substitutions I expect to see when the build runs (img) through Cloud BuildDeterminism
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.Nussbaum
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.Smoulder

© 2022 - 2024 — McMap. All rights reserved.