Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can we use dynamic jobs names in gitlab-ci.yml?

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.

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

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".

Is that even possible?

thks :)

like image 506
lepapareil Avatar asked Sep 10 '18 14:09

lepapareil


People also ask

Which file is used to specify the jobs within the GitLab CI pipeline?

gitlab-ci. yml file is a YAML file where you configure specific instructions for GitLab CI/CD. In this file, you define: The structure and order of jobs that the runner should execute.

How do you declare variables in GitLab Yml?

In GitLab, CI/CD variables can be defined by going to Settings » CI/CD » Variables, or by simply defining them in the . gitlab-ci. yml file. Variables are useful for configuring third-party services for different environments, such as testing , staging , production , etc.


2 Answers

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

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

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 there 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.

like image 88
AltGr Avatar answered Sep 18 '22 11:09

AltGr


No, it is not possible to have dynamic job names in GitLab CI.

like image 33
King Chung Huang Avatar answered Sep 18 '22 11:09

King Chung Huang