0

I am trying to create an environment variable in my cloud build job named "MERGE_COMMIT_SHA". I am using this in my deployment pipeline in Spinnaker.

I create the variable from a curl command, this is working. I am then able to echo the variable successfully also.

steps:
- name: gcr.io/cloud-builders/curl
  entrypoint: bash
  args: 
    - "-c"
    - |
     apt-get update -y
     apt-get install -y jq
     export MERGE_COMMIT_SHA=$$(curl -u user:$$GITHUB_TOKEN https://api.github.com/repos/ORG/REPO/pulls/$_PR_NUMBER | jq -r '.merge_commit_sha') 
     echo "The commit sha is" $$MERGE_COMMIT_SHA
     printenv
  secretEnv: 
    - GITHUB_TOKEN
options:
  env:
  - 'MERGE_COMMIT_SHA=$$MERGE_COMMIT_SHA'
availableSecrets:
  secretManager:
  - versionName: projects/project/secrets/GITHUB_TOKEN/versions/1
    env: 'GITHUB_TOKEN'

When I printenv in the job I see:

MERGE_COMMIT_SHA=MY Correct SHA

In the execution details of the job though, I see this:

Environment variables
MERGE_COMMIT_SHA   $MERGE_COMMIT_SHA

And in the streaming to pub/sub which is where I am trying to get this variable to pass to, I see this:

 "env": ["MERGE_COMMIT_SHA\u003d$MERGE_COMMIT_SHA"],

Am I doing something wrong on this? Or maybe there is a better way to do this?

The end goal of this is to pass the variable value that I create to spinnaker so that I can use it in my deployment jobs.

user17094440
  • 41
  • 1
  • 4
  • I don't understand the 2 latest piece of code. I don't know from where they come from. Did you forget to share some steps in your Cloud Build pipeline? – guillaume blaquiere Apr 07 '22 at 20:40
  • You may want to check this [post](https://stackoverflow.com/questions/51577871/environment-variables-in-google-cloud-build). – Catherine O Apr 08 '22 at 09:54
  • @guillaumeblaquiere Sorry if I wasn't clear on that. ``` Environment variables MERGE_COMMIT_SHA $MERGE_COMMIT_SHA ``` That comes from the cloud build execution details. That is the first place I would expect my value to show up. ``` "env": ["MERGE_COMMIT_SHA\u003d$MERGE_COMMIT_SHA"], ``` This comes from pubsub. We stream our execution details to pubsub after a cloud build job completes. – user17094440 Apr 08 '22 at 14:28

0 Answers0