可以从脚本中的管道中访问无安全变量

发布于 2025-02-07 21:28:46 字数 1613 浏览 3 评论 0原文

我正在尝试使用基本64的技术,将.ENV文件编码为管道无担保变量,如以下位置所述,但是创建的文件是空的:

我如何在bitbucket管道上运行一个env变量?

如何将变量传递给recredentials.json

image: node:16
definitions:

  caches:
    yarncustom: /usr/local/share/.cache/yarn
  steps:
    - step: &Build-step
        name: Build
        caches:
          - node
          - yarncustom
        script:
          - echo $ENV_FILE | base64 -d > .env.local
          - cat .env.local
          - yarn install
          - yarn build
        artifacts:
          - .next/**
          - node_modules/**
          - .env.local
    - step: &Deploy-step
        name: Deploy
        script:
          - pipe: atlassian/rsync-deploy:0.4.3
            variables:
              USER: $USER
              SERVER: $SERVER
              REMOTE_PATH: $REMOTE_PATH
              LOCAL_PATH: '.'
              EXTRA_ARGS: '--exclude-from=deployment-exclude-list.txt'
pipelines:
  branches:
    development:
      - step: *Build-step
      - step:
          <<: *Deploy-step
          deployment: test

。哪个有效,这意味着该变量根本不存在,尽管我读过的所有内容都表明这应该有效。

echo randomBase64String | base64 -d > .env.local

Bitbucket PiPLELINES的屏幕截图证明它存在并且不受约束:

I'm trying to use the technique of base64 encoding my .env file into a pipelines unsecured variable as described in the following places, but the file that is created is empty:

How can I run a env variables on bitbucket pipeline?

How to pass variables to credentials.json in bitbucket-pipelines?

image: node:16
definitions:

  caches:
    yarncustom: /usr/local/share/.cache/yarn
  steps:
    - step: &Build-step
        name: Build
        caches:
          - node
          - yarncustom
        script:
          - echo $ENV_FILE | base64 -d > .env.local
          - cat .env.local
          - yarn install
          - yarn build
        artifacts:
          - .next/**
          - node_modules/**
          - .env.local
    - step: &Deploy-step
        name: Deploy
        script:
          - pipe: atlassian/rsync-deploy:0.4.3
            variables:
              USER: $USER
              SERVER: $SERVER
              REMOTE_PATH: $REMOTE_PATH
              LOCAL_PATH: '.'
              EXTRA_ARGS: '--exclude-from=deployment-exclude-list.txt'
pipelines:
  branches:
    development:
      - step: *Build-step
      - step:
          <<: *Deploy-step
          deployment: test

I have tried running the following which works, which means that the variable is simply not there, although everything I have read suggests this should be working.

echo randomBase64String | base64 -d > .env.local

Screenshot of Bitbucket Piplelines to prove it exists and is unsecured:

enter image description here

What could I be missing?

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

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

发布评论

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

评论(2

慵挽 2025-02-14 21:28:46

您没有将正确的部署传递给build step

从屏幕截图上可以看出,env_file变量在test部署中定义,因此您需要将管道更改为:

pipelines:
  branches:
    development:
      - step:
          <<: *Build-step
          deployment: Test # This is required to fix your problem
      - step:
          <<: *Deploy-step
          deployment: Other-Deployment # Don't attempt to use Test deployment twice as it's not allowed.

You are not passing the correct deployment to the Build-step.

As can be seen on the screenshot, the ENV_FILE variable is defined in the Test deployment, so you'll need to change your pipeline to:

pipelines:
  branches:
    development:
      - step:
          <<: *Build-step
          deployment: Test # This is required to fix your problem
      - step:
          <<: *Deploy-step
          deployment: Other-Deployment # Don't attempt to use Test deployment twice as it's not allowed.
昨迟人 2025-02-14 21:28:46

我发现您无法在步骤之间访问部署变量。但是您可以在任何步骤中访问存储库级变量。因此,我创建了一个新的步骤,以获取回购级别变量,并将其保存为以后步骤的人工制品。如果有人对此有任何改进,我很想听听!

image: node:16
definitions:

  caches:
    yarncustom: /usr/local/share/.cache/yarn
  steps:
    - step: &Dev-step
        name: Env
        script:
          - echo $DEV_ENV | base64 -di > .env.local
        artifacts:
          - .env.local
    - step: &Build-step
        name: Build
        caches:
          - node
          - yarncustom
        script:
          - yarn install
          - yarn build
        artifacts:
          - .next/**
          - node_modules/**
    - step: &Deploy-step
        name: Deploy
        script:
          - pipe: atlassian/rsync-deploy:0.4.3
            variables:
              USER: $USER
              SERVER: $SERVER
              REMOTE_PATH: $REMOTE_PATH
              LOCAL_PATH: '.'
              EXTRA_ARGS: '--exclude-from=deployment-exclude-list.txt'
pipelines:
  branches:
    development:
      - step:
          <<: *Dev-step
      - step:
          <<: *Build-step
      - step:
          <<: *Deploy-step
          deployment: test

I found that you can't access deployment variables between steps. But you can access repository level variables in any step. So I created a new step to get the repo level variable and save it as an artefact for later steps. If anyone has any improvements on this I would love to hear it!

image: node:16
definitions:

  caches:
    yarncustom: /usr/local/share/.cache/yarn
  steps:
    - step: &Dev-step
        name: Env
        script:
          - echo $DEV_ENV | base64 -di > .env.local
        artifacts:
          - .env.local
    - step: &Build-step
        name: Build
        caches:
          - node
          - yarncustom
        script:
          - yarn install
          - yarn build
        artifacts:
          - .next/**
          - node_modules/**
    - step: &Deploy-step
        name: Deploy
        script:
          - pipe: atlassian/rsync-deploy:0.4.3
            variables:
              USER: $USER
              SERVER: $SERVER
              REMOTE_PATH: $REMOTE_PATH
              LOCAL_PATH: '.'
              EXTRA_ARGS: '--exclude-from=deployment-exclude-list.txt'
pipelines:
  branches:
    development:
      - step:
          <<: *Dev-step
      - step:
          <<: *Build-step
      - step:
          <<: *Deploy-step
          deployment: test
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文