如何为python Bitbucket Pipeline设置Postgres数据库模式

时间:2018-06-06 06:54:27

标签: postgresql bitbucket bitbucket-pipelines

我正在尝试将bitbucket管道与使用Postgres数据库的python包集成。

为了实现这一点,我使用的是Postgres服务,但是我无法在bitbucket-pipelines.yml中找到任何方法来填充数据库模式。

下面是我的bitbucket-pipeline.yml,现在我收到错误“bash:psql:command not found”

image: python:2.7.13
definitions:
    services:
      postgres:
         image: postgres
pipelines:
  default:
    - step:
        caches:
          - pip
        script:
          - python setup.py sdist
        services:
          - postgres
  branches:
    master:
      - step:
          name: Run unit/integration tests
          deployment: test
          caches:
            - pip
          script:
            - sudo apt-get update && sudo apt-get install -y postgresql-client
            - psql -c 'drop database if exists testdb;' -U postgres
            - psql -c 'create database testdb;' -U postgres
            - python setup.py sdist
            - python -m unittest discover tests/

1 个答案:

答案 0 :(得分:0)

这对我有用(我必须在apt-get之前删除sudos)

image: atlassian/default-image:2
  clone:
    depth: 5       # include the last five commits

  definitions:
    services:
      postgres:
        image: postgres
        environment:
          POSTGRES_DB: test_annotation
          POSTGRES_USER: user
          POSTGRES_PASSWORD: password

  pipelines:
    default:
      - step:
          caches:
            - node
          script:
            - apt-get update && apt-get install -y postgresql-client
            - PGPASSWORD=password psql -h localhost -p 5432 -U user test_annotation;
            - chmod 755 ./scripts/create-test-database.sh
            - ./scripts/create-test-database.sh
          services:
            - postgres

确保正确使用了服务,否则,数据库将无法启动。

朱利安