如何使用变量设置动态 gitlab 作业标签? [英] How to set a dynamic gitlab job tag with a variable?

查看:89
本文介绍了如何使用变量设置动态 gitlab 作业标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个动态作业,该作业可以根据给定的标签在两个 gitlab 运行器之间切换.我想用环境变量来做这件事,但似乎不能使用.以下工作:

I am trying to create a dynamic job that can switch between two gitlab runners depending on which tag it is given. I would like to do this with an environmental variable, but it seems this cannot be used. The following job:

runner_test:
  image: alpine
  tags:
    - $MY_RUNNER
  stage: deploy_main
  script:
    - echo foobar
  retry: 2

导致管道暂停并出现以下错误:此作业被卡住,因为您没有任何在线的活动跑步者或分配给他们的任何这些标签可用:$MY_RUNNER

Results in a paused pipeline with the error: This job is stuck because you don't have any active runners online or available with any of these tags assigned to them: $MY_RUNNER

推荐答案

目前不可用.目前有一个未解决的问题在请求此功能的待办事项中:https://gitlab.com/gitlab-org/gitlab-runner/-/issues/1809.

This is currently not available. There is currently an open issue which is in the backlog requesting this feature: https://gitlab.com/gitlab-org/gitlab-runner/-/issues/1809.

也许可以使用 rules扩展:

A work around perhaps, using rules and extends:

.template:
  stage: deploy_main
  script:
    - echo foobar

runner_test_1:
  extends: .template
  tags:
    - runner_1
  rules:
    - if: $RUNNER_TAG == runner_1
    
runner_test_2:
  extends: .template
  tags:
    - runner_2
  rules:
    - if: $RUNNER_TAG == runner_2

或类似的东西.

这篇关于如何使用变量设置动态 gitlab 作业标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆