使用 shell 部署 Google App Engine 的 Bitbucket 管道

Bitbucket pipeline to deploy Google App Engine using shell

我正在创建 bitbucket 管道,我在其中使用 shell 脚本,该脚本将采用环境名称。 根据环境名称,我将代码部署到不同的环境。

pipelines:
  default:
    - step:
        script:
          # Install Google Cloud SDK
          - export CLOUDSDK_CORE_DISABLE_PROMPTS=1
          # Google Cloud SDK is pinned for build reliability. Bump if the SDK complains about deprecation.
          - SDK_VERSION=127.0.0
          - SDK_FILENAME=google-cloud-sdk-${SDK_VERSION}-linux-x86_64.tar.gz
          - curl -O -J https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${SDK_FILENAME}
          - tar -zxvf ${SDK_FILENAME} --directory ${HOME}
          - export PATH=${PATH}:${HOME}/google-cloud-sdk/bin
          # Install Google App Engine SDK
          - GAE_PYTHONPATH=${HOME}/google_appengine
          - export PYTHONPATH=${PYTHONPATH}:${GAE_PYTHONPATH}
          - python scripts/fetch_gae_sdk.py $(dirname "${GAE_PYTHONPATH}")
          - echo "${PYTHONPATH}" && ls ${GAE_PYTHONPATH}
          # Install app & dev dependencies, test, deploy, test deployment
          - pip --quiet install -r requirements.txt -t lib/
          - echo "key = '${GOOGLE_API_KEY}'" > api_key.py
          - python test_main.py
          - echo ${GOOGLE_CLIENT_SECRET} > client-secret.json
          - gcloud auth activate-service-account --key-file client-secret.json
          - ./deploy.sh dev service-test here

我收到以下错误:

    + ./deploy.sh dev test-service
bash: ./deploy.sh: Permission denied

您只需在调用实际 bash 脚本之前添加“- bash”。在你的情况下是:

pipelines:
  default:
    - step:
        script:
          # Install Google Cloud SDK
          - export CLOUDSDK_CORE_DISABLE_PROMPTS=1
          # Google Cloud SDK is pinned for build reliability. Bump if the SDK complains about deprecation.
          - SDK_VERSION=127.0.0
          - SDK_FILENAME=google-cloud-sdk-${SDK_VERSION}-linux-x86_64.tar.gz
          - curl -O -J https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${SDK_FILENAME}
          - tar -zxvf ${SDK_FILENAME} --directory ${HOME}
          - export PATH=${PATH}:${HOME}/google-cloud-sdk/bin
          # Install Google App Engine SDK
          - GAE_PYTHONPATH=${HOME}/google_appengine
          - export PYTHONPATH=${PYTHONPATH}:${GAE_PYTHONPATH}
          - python scripts/fetch_gae_sdk.py $(dirname "${GAE_PYTHONPATH}")
          - echo "${PYTHONPATH}" && ls ${GAE_PYTHONPATH}
          # Install app & dev dependencies, test, deploy, test deployment
          - pip --quiet install -r requirements.txt -t lib/
          - echo "key = '${GOOGLE_API_KEY}'" > api_key.py
          - python test_main.py
          - echo ${GOOGLE_CLIENT_SECRET} > client-secret.json
          - gcloud auth activate-service-account --key-file client-secret.json
          - gcloud auth activate-service-account --key-file client-secret.json
          - bash ./deploy.sh dev service-test here