Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass values to a Gitlab CI Job

I have a GitLab ci job to download and build few files and then publish to another server. I have done a POC and was successful. The problem is that I would like to customize the job when triggered manually or via API. How can i pass the dynamic values(user given) to reflect in CI job (like a filename, format etc)?

I am using Windows runner.

I saw trigger variables and environment variables but can be retrieved while execution once the value is set in UI. I want a bit different where I will get the values from user.

Is it not possible in GitLab?

Edit:

A bit more info on how I'm using the pipeline. My pipeline has two stages - build and deploy. I want the build to run once, but I want to be able to call deploy multiple to deploy to different server. I can use the variable to determine to which server I want to deploy. Through GitLab UI this is possible - i can set variables for pipeline and also for job that overrides the pipeline variable. I just want to do the same thing through API.

like image 417
abhi88 Avatar asked Mar 28 '19 06:03

abhi88


People also ask

How do you pass variables in GitLab CI?

An alternative is to use Gitlab Variables. Go to your project page, Settings tab -> CI/CD, find Variables and click on the Expand button. Here you can define variable names and values, which will be automatically passed into the gitlab pipelines, and are available as environment variables there.

How do I inherit a group variable in GitLab?

If you have GitLab 9.4+, you can set up group-level environment variables like this: Navigate to your Group. Go to Settings > CI/CD > Variables . Group variables will be inherited by the group's projects and sub-groups.


1 Answers

You can pass variables when starting a pipeline: https://docs.gitlab.com/ee/ci/pipelines/#run-a-pipeline-manually

Pipelines can be manually executed, with predefined or manually-specified variables.

These variables can be also specified on the API call: https://docs.gitlab.com/ee/api/pipelines.html#create-a-new-pipeline

An array containing the variables available in the pipeline, matching the structure [{ ‘key’ => ‘UPLOAD_TO_S3’, ‘value’ => ‘true’ }]

like image 52
djuarezg Avatar answered Oct 19 '22 10:10

djuarezg