首页 > 解决方案 > 如何在 gitlab-ci.yaml 中使用变量文件/服务帐户文件

问题描述

我在 gitlab repo 中设置了包含 GCP 服务帐户 json 的变量文件。参考图片:

在此处输入图像描述

我需要服务帐户才能访问 BQ 以进行我的一项单元测试。如何在 gitlab-ci.yaml 中使用这个 SA?

这是我的一部分gitlab-ci

.test-template:
  image: python:3.7
  cache:
    key: ${CI_COMMIT_REF_NAME}
    paths: # specify paths to be cached
      - .cache/pip
      - venv/
  environment: 
    name: dev
  before_script:
    - # Maybe add in here
    - echo ${API_TOKEN}
    - python -V               # Print out python version for debugging
    - pip install virtualenv
    - virtualenv venv
    - source venv/bin/activate
    - pip install -r requirements.txt
    - cd tests/

  only:
    refs:
      - master
      - dev
  coverage: '/TOTAL.+ ([0-9]{1,3}%)/'

pre-test:
  stage: test
  extends: .test-template
  script:
    # - export ENV=local
    # - pip install -r ./requirements.txt
    - pytest pre_test.py -v

标签: pythongoogle-cloud-platformgitlabgitlab-ci

解决方案


推荐阅读