bitbucket pipeline - caches

本文介绍了如何在Bitbucket Pipeline中使用缓存来提高构建速度,针对使用poetry管理Python依赖的情况。由于poetry不直接支持缓存,作者转而使用pip缓存。通过更新requirements.txt,配置Bitbucket中的pip缓存,以及检查pipeline执行,作者发现虽然有缓存但只缓存了一部分依赖。需要注意的是,如果构建失败,将不会保存任何缓存。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在项目中想利用bitbucket pipeline的cache机制节省build时间

项目采用poetry 安装 python 依赖库, 在pipeline上每次执行安装耗时非常长。

 尝试用pipeline caches来引入poetry cache:

definitions:
  caches:
    sonar: ~/.sonar/cache
    poetry: ~/.poetry/cache
  services:
    docker:
      memory: 2048
  steps:
    - step: &code-style
        name: "Code Style"
        script:
          - pycodestyle --config .pycodestyle **/**.py
    - step: &sonar-scan
        image: atlassian/default-image:2
        name: "Sonar Scan and Quality Gate"
        size: 2x
        caches:
          - docker
        script:
          - pipe: sonarsource/sonarcloud-scan:1.1.0
          - pipe: sonarsource/sonarcloud-quality-gate:0.1.3
        services:
          - docker

pipelines:
  custom:
    regression-test:
      - variables:
          - name: AS_RPT_CUSTOMER
          - name: AS_RPT_MARKET
          - name: AS_RPT_DB_SCHEMA
          - name: AS_RPT_OPTIONS
      - step:
          name: "Test"
          size: 2x
          caches:
            - docker
            - poetry
          services:
            - docker
          artifacts:
            - test-reports/*.html
          script:
            - poetry install --no-root
            - pytest --market $AS_RPT_MARKET --schema $AS_RPT_DB_SCHEMA $AS_RPT_OPTIONS
              --html="test-reports/$AS_RPT_CUSTOMER-$BITBUCKET_BUILD_NUMBER.html"
              --html-title="$AS_RPT_CUSTOMER $AS_RPT_MARKET $AS_RPT_DB_SCHEMA Regression Test" $AS_RPT_CUSTOMER
          after-script:
            - pipe: atlassian/bitbucket-upload-file:0.1.8
              variables:
                BITBUCKET_USERNAME: $BITBUCKET_USER
                BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD
                FILENAME: "test-reports/$AS_RPT_CUSTOMER-$BITBUCKET_BUILD_NUMBER.html"

然并卵, poetry 安装依赖会从lock.file解析,并不会直接用到cache....

参考: https://python-poetry.org/docs/basic-usage/#initialising-a-pre-existing-project  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值