具有不同构建变量的Bitbucket管道

发布于 2025-01-29 03:10:56 字数 1951 浏览 3 评论 0 原文

我有一个简单的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"  

我正在使用存储库“部署”设置为部署阶段添加变量,但是当我作为部署时,我似乎没有一种访问这些阶段的方法:设置只能在管道的一个阶段使用。是否有人想出了一种在管道的构建阶段中解释不同构建环境变量的方法,这可以将我指向正确的方向?

I have a simple Vue.js project that utilizes Vite to build the distribution. I am utilizing dotenv to target specific environments for my deployment via different .env files such as .env and .env.dev where .env may contain

VITE_APP_TITLE=My Site (local)

and .env.dev might contain

VITE_APP_TITLE=My Site (dev)

Running vite build and vite build --mode dev generates the correct distribution with the appropriate substitutions, however, I cannot seem to get a similar behavior from Bitbucket pipelines.

My build pipeline currently looks like this

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"  

I am utilizing the repository "Deployments" setting to add variables for the deployment stage but there does not appear to be a way for me to access these for the build stage as the deployment: setting can only be used during one stage of the pipeline. Has anyone figured out a way to account for different build environment variables during the build stage of the pipeline that could point me in the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝影如岚 2025-02-05 03:10:56

如果需要完全控制,则需要使用。但这不允许轻松自动化。

因此,对于自动化,关于部署何时会发生变化的问题?如果它基于分支/标签,则只需在每个不同部署的设置中进行安装中的设置,然后进行单独的管道即可。如果一切都以相同的方式进行,那么您对如何控制它会更加限制。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文