如何在环境url[Gitlab CI]中定义环境变量

如何在环境url[Gitlab CI]中定义环境变量,gitlab,gitlab-ci,environment,Gitlab,Gitlab Ci,Environment,请帮忙。我在使用CI工具时遇到问题 这是我的.gitlab ci.yaml stages: - test test: stage: test environment: name: test url: https://word.mymusise.com/env_test.txt script: echo "Running tests TEST=$TEST" 我已经在EnvDocker>Pipelines>Environments 但是它没有从https://wo

请帮忙。我在使用CI工具时遇到问题

这是我的
.gitlab ci.yaml

stages:
  - test

test:
  stage: test
  environment:
    name: test
    url: https://word.mymusise.com/env_test.txt
  script: echo "Running tests TEST=$TEST"
我已经在
EnvDocker>Pipelines>Environments

但是它没有从
https://word.mymusise.com/env_test.txt
在CI作业中

Running with gitlab-runner 11.4.2 (cf91d5e1)
  on gitlab-ci runner a0e18516
Using Docker executor with image ubuntu:16.04 ...
Pulling docker image ubuntu:16.04 ...
Using docker image sha256:2a697363a8709093834e852b26bedb1d85b316c613120720fea9524f0e98e4a2 for ubuntu:16.04 ...
Running on runner-a0e18516-project-123-concurrent-0 via gitlab...
Fetching changes...
HEAD is now at d12c05b Update .gitlab-ci.yml
From https://gitlab.kingdomai.com/mymusise/envdocker
   d12c05b..1a3954f  master     -> origin/master
Checking out 1a3954f8 as master...
Skipping Git submodules setup
$ echo "Running tests TEST=$TEST"
Running tests TEST=
Job succeeded
我在
https://word.mymusise.com/env_test.txt
,但它似乎不起作用

我该怎么办。。。奥兹


Gitlab版本:11.4.0-ee

您希望运行文本文件中的命令,该文本文件可通过http协议访问

使用
curl
可以下载文件并在
curl
的标准输出上打印。使用命令替换
$()
可以获取标准输出。然后可以执行命令本身(非常不安全,可能存在多个转义问题)

更安全的替代方法是下载文件并执行/源代码

 script: 
   - curl "$url" > ./run_this.sh
   # don't forget to add executable right to the file ;)
   - chmod +x ./run_this.sh
   - source ./run_this.sh
   # pick out the trash
   - rm ./run_this.sh
   # rest of your script.
   - echo "Running tests TEST=$TEST"

下载shell脚本并执行它是自动化任务的常用方式,通常使用
curl-url | bash
。gitlab不支持“本机”支持它,我认为也不应该支持。

您需要手动执行此操作。为什么希望gitlab为您做这件事
$(curl“$url”)
@KamilCuk谢谢,但是如何手动完成呢?是的,我希望gitlab为我做这件事。我应该在脚本中添加
$(curl“$url”)
?如果这样做,什么是
environment:name:testurl:$url
doThanks!使用
curl-url | bash
加载我的环境是一种很好的方法。但是我仍然想知道Gitlab CI在保护环境方面做了什么。(受保护的环境)[请问您是如何管理不同环境中的配置的(测试、构建、部署)我的目标是不让任何复杂的东西和脚本在我自己的计算机上完全运行,因此我可以在提交之前对它们进行测试,通常使用尽可能少的变量/参数。我的项目是C-ish,所以它只是“构建”对于cmake,有时它会测试,实际上没有“环境”会影响它。对于部署,真正需要的是一个私有ssh密钥,它作为隐藏变量存储在gitlab中,作为脚本的stdin和作为参数传递的服务器地址。
 script: 
   - curl "$url" > ./run_this.sh
   # don't forget to add executable right to the file ;)
   - chmod +x ./run_this.sh
   - source ./run_this.sh
   # pick out the trash
   - rm ./run_this.sh
   # rest of your script.
   - echo "Running tests TEST=$TEST"