我们可以在 gitlab-ci.yml 中使用动态作业名称吗? [英] can we use dynamic jobs names in gitlab-ci.yml?

查看:47
本文介绍了我们可以在 gitlab-ci.yml 中使用动态作业名称吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从 jenkins 迁移到 gitlab,我希望能够使用动态作业名称,以便在管道摘要中直接获取一些信息,而无需单击每个作业等....在 jenkins 中,我们可以立即看到传递给我们作业的参数,而在 gitlab-ci 中并非如此.

I have to migrate from jenkins to gitlab and I would like to be able to use dynamic job names in order to have some information directly in the pipeline summary without having to click on each job etc.... in jenkins we can immediately see the parameters passed to our job and this is not the case in gitlab-ci.

我的测试运行器在 Windows 上,我尝试将 yml 定义如下:

My test runner being on a windows I tried to define the yml as follows:

job_%myParam%:
  stage: build
  script:
    - set>varList.txt
  artifacts:
    paths:
    - varList.txt

当我使用 %myParam%=true 开始我的工作时,该变量不会在工作名称中解释,因此它采用 job_%myParam% 的名称而不是预期的job_true".

When I start my job with %myParam%=true, the variable is not interpreted in the job name and so it takes the name of job_%myParam% instead of expected "job_true".

这可能吗?

谢谢:)

推荐答案

从 gitlab 12.9 开始,这可以使用 trigger子管道——虽然有点涉及:

As of gitlab 12.9, this can be done using trigger and child pipelines — although a little involved:

引用 gitlab 文档中的示例:

Quoting the example from the gitlab doc:

generate-config:
  stage: build
  script: generate-ci-config > generated-config.yml
  artifacts:
    paths:
      - generated-config.yml

child-pipeline:
  stage: test
  trigger:
    include:
      - artifact: generated-config.yml
        job: generate-config

在您的情况下,您可以将 job_%myParam% 的定义放在 job.yml.in 中,然后让脚本 generate-ci-config be eg sed "s/%myParam%/$PARAM/g" job.yml.in.

In your case, you would put the definition of job_%myParam% in job.yml.in, then have the script generate-ci-config be e.g. sed "s/%myParam%/$PARAM/g" job.yml.in.

这当然只是更改名称可能有点多,而且它们将是与附加阶段相关的成本;但它确实回答了这个问题,并且可能有助于做更多事情,例如在同一管道中从不同版本的参数开始.

This is probably a bit much for just changing the names of course, and their will be a cost associated to the additional stage; but it does answer the question, and may be useful to do more, like start with different versions of the parameter in the same pipeline.

这篇关于我们可以在 gitlab-ci.yml 中使用动态作业名称吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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