CircleCI-Public / gcp-cli-orb

Install and configure the Google Cloud CLI (gcloud)
https://circleci.com/orbs/registry/orb/circleci/gcp-cli
MIT License
10 stars 34 forks source link

`pyenv-version-name: command not found` when running "GCloud version" on `machine: true` #22

Closed nathanhleung closed 4 years ago

nathanhleung commented 4 years ago

Orb version

1.8.4

What happened

Running with machine: true

Job "GCloud version" failed with this output:

#!/bin/bash -eo pipefail
gcloud version
/opt/circleci/.pyenv/libexec/pyenv-exec: line 24: pyenv-version-name: command not found
/opt/circleci/.pyenv/libexec/pyenv-exec: line 24: pyenv-version-name: command not found
/opt/circleci/.pyenv/libexec/pyenv-exec: line 24: pyenv-version-name: command not found
/opt/circleci/.pyenv/libexec/pyenv-exec: line 24: pyenv-version-name: command not found
/opt/circleci/.pyenv/libexec/pyenv-exec: line 24: pyenv-version-name: command not found

Exited with code exit status 127
CircleCI received exit code 127

Workflow URL: https://app.circleci.com/jobs/github/Jupiter-Inc/jupiter-platform/3768

Expected behavior

The gcp cli is installed successfully, without failure.

dsayling commented 4 years ago

@nathanhleung

I tried replicating the environment similar to yours. I'm not quite sure why, but when you download hub and append to the $BASH_ENV something mucks with the path that messes this up. Below is a machine executor where I ran the following config

version: 2.1

orbs:
  gcp-cli: circleci/gcp-cli@1.8
jobs: 
  sample:
    machine: true
    steps:
      - gcp-cli/install
      - gcp-cli/initialize

workflows:
  sample_wf:
    jobs:
      - sample

After running this config, gcloud was sucessfully installed. I then ssh'ed onto the machine and ran your step to install hub manually and was then presented with the error.

circleci@default-39f4e924-a473-44bc-89a4-a83972391423:~$ gcloud version
Google Cloud SDK 169.0.0
alpha 2017.08.28
beta 2017.08.28
bq 2.0.25
core 2017.08.28
gcloud 
gsutil 4.27
circleci@default-39f4e924-a473-44bc-89a4-a83972391423:~$ echo $BASH_ENV
/tmp/.bash_env-5f9085f0894c353e23d39d13-0-build
circleci@default-39f4e924-a473-44bc-89a4-a83972391423:~$ cat $(echo $BASH_ENV)
source ~/google-cloud-sdk/path.bash.inc
circleci@default-39f4e924-a473-44bc-89a4-a83972391423:~$ echo ^C^C
circleci@default-39f4e924-a473-44bc-89a4-a83972391423:~$ ^C
circleci@default-39f4e924-a473-44bc-89a4-a83972391423:~$ cd ~/Downloads
-bash: cd: /home/circleci/Downloads: No such file or directory
circleci@default-39f4e924-a473-44bc-89a4-a83972391423:~$ curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1
git version 2.14.2
hub version 2.14.1
Warning: We recommend supplying the GITHUB_TOKEN environment variable to avoid
being prompted for authentication.
circleci@default-39f4e924-a473-44bc-89a4-a83972391423:~$ echo "export PATH=$(pwd)/bin:$PATH" >> $BASH_ENV
circleci@default-39f4e924-a473-44bc-89a4-a83972391423:~$ source^C
circleci@default-39f4e924-a473-44bc-89a4-a83972391423:~$ source $BASH_ENV
circleci@default-39f4e924-a473-44bc-89a4-a83972391423:~$ gcloud
/opt/circleci/.pyenv/libexec/pyenv-exec: line 24: pyenv-version-name: command not found

Without spending a ton of time, I'm not sure if this is a problem with the way ~/google-cloud-sdk/path.bash.inc is sourced or the additions you made to $BASH_ENV. Could you provide some more context around how you encountered this? Was this working in a previous build with a different machine image or different orb version?

dsayling commented 4 years ago

@nathanhleung - we are investigating some issues with pyenv in some of the machine images. However, the latest machine image appears to work as expected. You can set this by updating machine: true to

machine:
      image: ubuntu-2004:202010-01

machine: true still provides an old default image. This old default image is still 14.04 based. We are now expecting users to specify the version of machine images, see the updated docs for more details

dsayling commented 4 years ago

@nathanhleung, you can thank @lokst for this fix. The issue is with the way the PATH is being updated here in your config, echo "export PATH=$(pwd)/bin:$PATH" >> $BASH_ENV needs to be echo 'export PATH=$(pwd)/bin:$PATH' >> $BASH_ENV. In double quotes the $PATH is being evaulated before its appended to $BASH_ENV, single quotes avoids this evaulation and ensures $PATH is the text appended to $BASH_ENV.

nathanhleung commented 4 years ago

Thank you for the quick response!