Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to pull BRANCH_NAME from cloud build

Per doc https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values

I supposed to pull $BRANCH_NAME but somehow it is not consistent. Sometimes it shows repo name and sometimes is nothing.

Here is my step

steps:
  - name: "gcr.io/cloud-builders/go"
    env:
      - "PROJECT_ROOT=blah"
      - "GOOS=linux"
      - "GOARCH=amd64"
      - "CGO_ENABLED=0"
    args:
      [
        "install",
        "-ldflags",
        "-d -s -w -X main.version=${TAG_NAME} -X main.commit=${SHORT_SHA} -X main.branch=${BRANCH_NAME}",
        "-a",
        "-tags",
        "netgo",
        "-installsuffix",
        "netgo",
        "blah/cmd/svc-api",
      ]

this is what I see on console:

Step #0 - "go-install": Running: go install -ldflags -d -s -w -X main.version=0.0.6p20-dev -X main.commit=ebf5281 -X main.branch= -a -tags netgo -installsuffix netgo blah/service

from my service start:

I am missing branch name.

Service : 2019/02/27 17:04:06.570856 main.go:135: TRACE MAIN : Started : Service Initializing version "0.0.6p20-dev" : **""** : "ebf5281"
like image 737
Askar Avatar asked Jan 28 '26 21:01

Askar


1 Answers

It seems cos my build is based on tag triggering there is no passing branch name. But the solution I found is to use substitutions during the build process.

https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values

like image 71
Askar Avatar answered Feb 01 '26 10:02

Askar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!