Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform 在Google Cloud Build中使用Google Cloud Secret作为环境变量_Google Cloud Platform_Continuous Integration_Google Cloud Build - Fatal编程技术网

Google cloud platform 在Google Cloud Build中使用Google Cloud Secret作为环境变量

Google cloud platform 在Google Cloud Build中使用Google Cloud Secret作为环境变量,google-cloud-platform,continuous-integration,google-cloud-build,Google Cloud Platform,Continuous Integration,Google Cloud Build,我正在使用Cloud Build将我的节点应用程序部署到Google Cloud Run,我想在构建过程中运行一些测试。我的测试需要一些环境变量,所以我一直在遵循这一点 本指南作了如下说明: 注意:要在环境变量中使用secret,需要在 变量名加下划线“\u1”,并使用 “(”。例如:_VARIABLE_NAME=$(cat password.txt)&&echo-n \)_变量名 然而,我不太清楚如何实施这一点。 我在我的cloudbuild.yaml中尝试了以下内容 -id:执行测试 名称:

我正在使用Cloud Build将我的节点应用程序部署到Google Cloud Run,我想在构建过程中运行一些测试。我的测试需要一些环境变量,所以我一直在遵循这一点

本指南作了如下说明:

注意:要在环境变量中使用secret,需要在 变量名加下划线“\u1”,并使用 “(”。例如:_VARIABLE_NAME=$(cat password.txt)&&echo-n \)_变量名

然而,我不太清楚如何实施这一点。 我在我的
cloudbuild.yaml
中尝试了以下内容

-id:执行测试
名称:节点
args:[“'u VAR'u ONE=$(cat VAR ONE.txt)”,'u VAR'u TWO=$(cat VAR TWO.txt)','jest-V']
返回以下内容:
错误:找不到模块'/workspace/\u VAR\u ONE=$(cat VAR ONE.txt)
。 我还尝试了上述注释中提到的一些转义变体,但它们导致了相同的错误

将秘密作为环境变量输入代码的最佳方法是什么? 另外,如果我需要使用多个环境变量,那么使用带有
.env
文件的Cloud KMS是否更好


谢谢

您似乎没有正确使用
节点提供的
入口点
。您正在有效地运行以下命令:

node _VAR_ONE=$(cat var-one.txt) _VAR_TWO=$(cat var-two.txt) jest -V
我想离题一会儿,说这个模式在节点中不起作用,您需要在调用
Node
之前先指定环境变量,例如
VAR\u ONE=$(cat foo.txt)VAR\u TWO=bar Node run test

不管怎么说,我认为你想要的是:

_VAR_ONE=$(cat var-one.txt) _VAR_TWO=$(cat var-two.txt) jest -V
这就是我们将如何做到这一点-假设您有一个前一步,在前一步中将机密内容写入文件
var one.txt
var two.txt
-下面是您将如何在
节点
步骤中使用它,这只是从命令行运行命令时使用环境变量的标准方式:

- id: Execute tests
  name: node
  entrypoint: '/bin/bash'
  args:
     '-c', 
     '_VAR_ONE=$(cat var-one.txt) _VAR_TWO=$(cat var-two.txt) jest -V'
  ]

您需要确保在节点环境中使用指定的变量(即
process.env.\u VAR\u ONE
process.env.\u VAR\u TWO
)。我认为您不需要在此处添加
\uuu
字符前缀,但我还没有对其进行测试以确认这一点。你可以试试上面的方法,我想这会让你走得更远。

你好。我想根据你的描述,你可以在这里找到一些好信息()。