我正在将我的react应用程序部署到s3桶中,我有很多env变量,所以问题是如何处理bitbucket管道中的env变量?
管道误差
+ npm run build
> app@0.1.0 build /opt/atlassian/pipelines/agent/build
> env-cmd -f .env.prod react-scripts build && cp build/index.html build/200.html
Error: Failed to find .env file at path: .env.prod
at getEnvFile (/opt/atlassian/pipelines/agent/build/node_modules/env-cmd/dist/get-env-vars.js:40:19)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! app@0.1.0 build: `env-cmd -f .env.prod react-scripts build && cp build/index.html build/200.html`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the app@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-03-01T10_17_14_844Z-debug.logbitbucket-pipeline.yml
image: node:10
# Workflow Configuration
pipelines:
default:
- parallel:
- step:
name: Build and Test
caches:
- node
script:
- npm install
# CI=true in default variables for Bitbucket Pipelines https://support.atlassian.com/bitbucket-cloud/docs/variables-in-pipelines/
branches:
master:
- parallel:
- step:
name: Build and Test
caches:
- node
script:
- npm install
# CI=true in default variables for Bitbucket Pipelines https://support.atlassian.com/bitbucket-cloud/docs/variables-in-pipelines/
- npm run build
artifacts:
- build/**
- step:
name: Security Scan
script:
# Run a security scan for sensitive data.
# See more security tools at https://bitbucket.org/product/features/pipelines/integrations?&category=security
- pipe: atlassian/git-secrets-scan:0.5.1
- step:
name: Deploy to Production
deployment: Production
trigger: manual
clone:
enabled: false
script:
# sync your files to S3
- pipe: atlassian/aws-s3-deploy:1.1.0
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: $S3_BUCKET
LOCAL_PATH: 'build'
# triggering a distribution invalidation to refresh the CDN caches
- 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: '123xyz'发布于 2022-08-25 15:12:01
到目前为止,我找到的最好的解决方案是使用bitbucket变量,并将它们传递到管道中。支持文章中的相关片段:
工作空间变量
可以从属于工作区的所有存储库访问为工作区指定的变量。您必须是管理员才能管理工作区变量。
从左下角的化身中,选择一个工作区。
选择左侧导航侧边栏上的设置以打开工作区设置。在左边的菜单中,转到管道>工作区变量。
工作区变量可以被存储库变量覆盖。
对于属于团队或帐户的任何存储库(私有存储库或公共存储库),所有用户都可以访问工作区变量。
您必须是管理变量的工作区或存储库的管理员。
https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/
发布于 2022-03-01 16:48:23
只需在脚本中添加一行您需要变量并加载文件:
- export $(cat .env | xargs)https://stackoverflow.com/questions/71306939
复制相似问题