Bitbucket Pipelines部署按钮14天后变灰:工件过期问题求助
我配置了Bitbucket Pipeline,通过官方Pipe完成构建后将工件上传至Bitbucket下载区。部署步骤已明确设置download: false,不依赖Pipeline内置机制下载工件,而是直接从Bitbucket获取。但14天后部署按钮变为灰色,工件显示已过期,尽管本不应依赖内置工件存储。
相关配置代码如下:
image: mcr.microsoft.com/dotnet/sdk:6.0 definitions: steps: - step: &build-.net name: Build .Net script: - apt-get update && apt-get install zip -y - export CONFIGURATION=Release - dotnet build -c ${CONFIGURATION} - dotnet publish -c ${CONFIGURATION} - cd Web/bin/Release/net6.0/publish && zip -r ../../../../../${BITBUCKET_REPO_SLUG}_${BITBUCKET_BRANCH////_}_${BITBUCKET_BUILD_NUMBER}.zip * artifacts: - app*.zip - step: &upload-artifacts name: Upload Release Artifacts to Bitbucket script: - pipe: atlassian/bitbucket-upload-file:0.3.4 variables: BITBUCKET_USERNAME: $BITBUCKET_USERNAME BITBUCKET_APP_PASSWORD: '$BITBUCKET_APP_PASSWORD' FILENAME: '${BITBUCKET_REPO_SLUG}_${BITBUCKET_BRANCH////_}_${BITBUCKET_BUILD_NUMBER}_*.zip' - step: &deploy name: Deploy to Dev deployment: Dev runs-on: - self.hosted - windows script: - Download Artifact Script - New-Item 'publish' -ItemType Directory - $BUILD_DIR = (Get-Location).Path - Get-ChildItem -Filter *_Backend.zip | Expand-Archive -DestinationPath publish -Force - msdeploy - parameters pipelines: default: - step: *build-.net - step: *deploy - step: <<: *deploy name: Deploy to QA deployment: QA trigger: manual - step: <<: *deploy name: Deploy to Regression deployment: Regression trigger: manual branches: release/*: - step: *build-.net - step: *upload-artifacts - step: <<: *deploy name: Deploy to Production deployment: production trigger: manual artifacts: download: false
确认zip文件已成功上传至Bitbucket,且14天内执行部署步骤时能正常从Bitbucket下载工件。
尽管你在部署步骤设置了download: false,但构建步骤中定义的artifacts字段会让Bitbucket Pipeline自动将匹配的工件存储到内置的工件存储中,且手动触发的部署步骤会默认关联该构建的内置工件。Bitbucket内置工件的保留期为14天,过期后系统会标记该构建的工件不可用,进而导致关联的手动部署按钮变灰,即使你的部署脚本实际使用的是上传到Bitbucket下载区的独立工件。
移除构建步骤的
artifacts配置
既然不依赖内置工件存储,直接删除&build-.net步骤中的artifacts块:- step: &build-.net name: Build .Net script: - apt-get update && apt-get install zip -y - export CONFIGURATION=Release - dotnet build -c ${CONFIGURATION} - dotnet publish -c ${CONFIGURATION} - cd Web/bin/Release/net6.0/publish && zip -r ../../../../../${BITBUCKET_REPO_SLUG}_${BITBUCKET_BRANCH////_}_${BITBUCKET_BUILD_NUMBER}.zip * # 移除以下两行 # artifacts: # - app*.zip这样Bitbucket就不会再保存内置工件,部署步骤也不会再关联到过期的内置工件。
为所有手动部署步骤添加
download: false
当前仅release/*分支的Production部署步骤设置了该配置,default分支下的QA、Regression手动部署步骤也需要添加,避免系统尝试下载不存在的内置工件:pipelines: default: - step: *build-.net - step: *deploy - step: <<: *deploy name: Deploy to QA deployment: QA trigger: manual artifacts: download: false - step: <<: *deploy name: Deploy to Regression deployment: Regression trigger: manual artifacts: download: false验证部署脚本独立性
确认你的Download Artifact Script确实是通过Bitbucket API或下载区链接获取工件,完全不依赖Pipeline内置的工件路径或变量,确保部署流程与内置工件存储彻底解耦。
内容的提问来源于stack exchange,提问作者GREGGROUNDHOG

