简体   繁体   English

是否可以在.gitlab-ci.yml 中使用动态变量?

[英]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.

相关问题 使用 PWD 在.gitlab-ci.yml 中定义变量时出错 - Error using the PWD to define variables in .gitlab-ci.yml 如何在 .gitlab-ci.yml 中使用 AWS CLI 和 kubectl - How to use AWS CLI and kubectl in .gitlab-ci.yml 如何在 windows 上使用 gitlab-ci-multi-runner 访问 gitlab-ci.yml 中的变量 - How to access variables in gitlab-ci.yml using gitlab-ci-multi-runner on windows 如何在.gitlab-ci.yml中定义变量以在运行时询问输入变量 - How to define variables in .gitlab-ci.yml to ask for input variable during runtime 使用 gitlab-ci.yml 中的 awk 命令杀死 docker 容器 - Kill a docker container using awk command in gitlab-ci.yml 条件 after_script in.gitlab-ci.yml - conditional after_script in .gitlab-ci.yml 用于编译 Go 二进制文件的 Simple.gitlab-ci.yml 文件 - Simple .gitlab-ci.yml file for compiling a Go binary 如何制作一个简单的 GitLab Ci/CD gitlab-ci.yml 文件来构建 Angular 项目? - How to make a simple GitLab Ci/CD gitlab-ci.yml file to build an Angular project? 如何在没有 GitLab Runner 的远程服务器上使用 gitlab-ci.yml 自动部署? - How can i auto deploy with gitlab-ci.yml on a remote server without GitLab Runner? 使用 gitlab-ci.yml 管道测试 python 程序时出现问题 - Problem using MPI in a python program when testing it with a gitlab-ci.yml pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM