How to use environment variables in the checkout step?

Hi I’m developing with Go, Dep.
When go commands something like go test it’s necessary to checkout the git revision in the $GOPATH because Dep requires.

So I tried below.

version: 2
    - image: golang

      CUSTOM_WORK_DIR: /go/src/

      - run:
          name: make go source directory
          command: |
            mkdir -p ${CUSTOM_WORK_DIR}

      - checkout:
          path: ${CUSTOM_WORK_DIR}

      - run:
          name: go get dep
          command: |
            go get -u

      - run:
          name: setting go environments
          command: |
            cd ${CUSTOM_WORK_DIR}
            dep ensure

But error occurred at the build in CircleCI.

setting go environments00:00
Exit code: 1
#!/bin/bash -eo pipefail
dep ensure
could not find project Gopkg.toml, use dep init to initiate a manifest
Exited with code 1

It is determined that the environment variable is empty and checked out for an empty directory.

How can i use environment variables in checkout?

As I understand it, some parts of the config can use env vars, some can’t - I suspect the code behind each one was written independently.

You can use a shell script instead of the checkout command though - copy the code echoed in one of your old runs for checkout, and then put that in a run step. You can use env vars there.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.