可以从脚本中的管道中访问无安全变量
我正在尝试使用基本64的技术,将.ENV文件编码为管道无担保变量,如以下位置所述,但是创建的文件是空的:
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:
What could I be missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有将正确的
部署
传递给build step
。从屏幕截图上可以看出,
env_file
变量在test
部署中定义,因此您需要将管道更改为:You are not passing the correct
deployment
to theBuild-step
.As can be seen on the screenshot, the
ENV_FILE
variable is defined in theTest
deployment, so you'll need to change your pipeline to:我发现您无法在步骤之间访问部署变量。但是您可以在任何步骤中访问存储库级变量。因此,我创建了一个新的步骤,以获取回购级别变量,并将其保存为以后步骤的人工制品。如果有人对此有任何改进,我很想听听!
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!