[英]Is it possible to use dynamic variables in .gitlab-ci.yml?
For example, I want to store some results from API call:例如,我想存储 API 调用的一些结果:
variables:
DYNAMIC_VAR: $(curl http://ifconfig.me)
Unfortunately no, you cannot do this. 不幸的是,您不能这样做。
If you only need to use this var in a single job, then it's simple: 如果您只需要在一个作业中使用此var,则很简单:
job:
script:
- DYNAMIC_VAR=$(curl http://ifconfig.me)
- echo "Using $DYNAMIC_VAR here ..."
However if you need to pass this var between jobs, at the moment it's not directly possible, but you can do it via artifacts. 但是,如果您需要在作业之间传递此var,则目前尚无法直接实现,但可以通过工件进行。
See example here: https://stackoverflow.com/a/56818718/902415 在此处查看示例: https : //stackoverflow.com/a/56818718/902415
You will have to use Artifact or Cache if you have to use this information in other jobs otherwise above answer is the perfect solution.如果您必须在其他工作中使用此信息,则必须使用 Artifact 或 Cache,否则上述答案是完美的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.