在项目中想利用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

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

被折叠的 条评论
为什么被折叠?



