具有不同构建变量的Bitbucket管道
我有一个简单的vue.js项目,该项目利用Vite来构建分布。我正在利用dotenv通过不同的.ENV文件(例如.env 和 .env.dev )来针对我部署的特定环境,其中 .env 可以包含
VITE_APP_TITLE=My Site (local)
和.env.dev可能包含
VITE_APP_TITLE=My Site (dev)
运行 vite build
和 vite build -mode dev
以适当的替换生成正确的分布,但是,我似乎无法获得类似的Bitbucket管道的行为。
我的构建管道目前看起来像这样,
image: node:14
pipelines:
branches:
develop:
- step:
name: Build and Test
caches:
- node
script:
- npm install
# - npm test
- step:
name: Run build
script:
- npm install
- npm run build:dev
artifacts:
- dist/**
caches:
- node
- step:
name: Deploy to dev
deployment: dev
script:
- echo "Deploying to dev environment"
- pipe: atlassian/aws-s3-deploy:0.3.8
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
S3_BUCKET: $AWS_BUCKET
LOCAL_PATH: 'dist'
ACL: 'public-read'
- step:
name: Invalidate Cloudfront Cache
script:
- pipe: atlassian/aws-cloudfront-invalidate:0.6.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
DISTRIBUTION_ID: $AWS_DISTRIBUTION_ID
PATHS: "/index.html"
我正在使用存储库“部署”设置为部署阶段添加变量,但是当我作为部署时,我似乎没有一种访问这些阶段的方法:设置只能在管道的一个阶段使用。是否有人想出了一种在管道的构建阶段中解释不同构建环境变量的方法,这可以将我指向正确的方向?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果需要完全控制,则需要使用。但这不允许轻松自动化。
因此,对于自动化,关于部署何时会发生变化的问题?如果它基于分支/标签,则只需在每个不同部署的设置中进行安装中的设置,然后进行单独的管道即可。如果一切都以相同的方式进行,那么您对如何控制它会更加限制。
If you want full control, you would need to go with custom steps and variables. But this doesn't allow for easy automation.
So for automation it is about question on when the deployment end would change? If it's based on the branch/tag, then you would just do a separate pipeline with the settings hardcoded into it per different deployment. If it's all going thru the same way, then you are more limited on how to control it.