【问题标题】:How should i write the command in .cy-gitlab.yml?我应该如何在 .cy-gitlab.yml 中编写命令?
【发布时间】:2022-01-23 23:25:03
【问题描述】:

我想将表达式写入文件

 - '{ "FRONTEND_URL":"http://$(pulumi stack output frontendUrl)" } >> cypress.env.json'

现在我收到错误消息

Outputs:
    backendUrl : "backend-loadbalance-6ac6577-668084404.eu-north-1.elb.amazonaws.com"
   frontendUrl: "frontend-loadbalance-58e3866-1753808242.eu-north-1.elb.amazonaws.com"
 Resources:
    60 unchanged
 Duration: 12s  
$ BACKEND_URL=http://$(pulumi stack output backendUrl)/helloworld >> test.env
$ { "FRONTEND_URL":"http://$(pulumi stack output frontendUrl)" } >> cypress.env.json
/bin/bash: eval: line 148: syntax error: unexpected end of file

这个命令怎么写?

【问题讨论】:

    标签: bash gitlab-ci pulumi


    【解决方案1】:

    嗯,首先你的 bash 语法是关闭的。我不确定您是否真的想在 bash 中使用 {}。看起来你的意思是让它成为 JSON 对象的一部分,而不是 bash 脚本的一部分。

    但要完成您最终想做的事情,您可以使用 jq 或 jo 来制作/编辑您的 JSON 文件。这将很有帮助,特别是如果您的变量可能包含需要在 JSON 中转义的字符。

    假设您有一个现有的cypress.env.json,您想使用jq 修改以包含两个新变量:

    script: |
     # install jq if needed!
     FRONTEND_URL="$(pulumi stack output frontendUrl)"
     BACKEND_URL="$(pulimi stack output backendUrl)"
     cat cypress.env.json | \
       jq --arg FRONTEND_URL "$FRONTEND_URL" \
          --arg BACKEND_URL "$BACKEND_URL" \
          '.FRONTEND_URL = $FRONTEND_URL | .BACKEND_URL = $BACKEND_URL' > new.json
     cp new.json cypress.env.json
    

    作为一个最小的例子:

    $ cat cypress.env.json  # the existing file
    {"FOO": "bar"}
    $ FRONTEND_URL="foobar.frontend"
    $ BACKEND_URL="foobar.backend"
    $ cat cypress.env.json | \
       jq --arg FRONTEND_URL "$FRONTEND_URL" \
          --arg BACKEND_URL "$BACKEND_URL" \
          '.FRONTEND_URL = $FRONTEND_URL | .BACKEND_URL = $BACKEND_URL' > new.json
    $ cat new.json # new file created with jq
    {
      "FOO": "bar",
      "FRONTEND_URL": "foobar.frontend",
      "BACKEND_URL": "foobar.backend"
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-22
      • 2020-07-16
      • 1970-01-01
      • 2013-05-28
      • 2010-12-19
      • 1970-01-01
      • 1970-01-01
      • 2015-03-22
      相关资源
      最近更新 更多