Gitlab CI/CD pre-filled variables on manual job

Viewed 6277

I'm looking for the right way to set up a variable when I launch a job manually. I tried :

stages:
  - test 

my_job:
  stage: test 
  script:
    - echo "HEY"
  variables:
    FIRST_VARIABLE: "my_variable"
    SECOND_VARIABLE: 
      value: "a"
      description: "b"
  when: manual

I want my SECOND_VARIABLE to appear into the following VARIABLES field, with a pre-field value : a. enter image description here

Unfortunatly, I got some error trying "variables config should be a hash of key value pairs" error.

I tried with the gitlab documentation (cf variables), but it fails.

Can you help me to solve this problem ?

3 Answers

It is possible in GitLab 13.7+ and works only with global variables:

variables:
  DEPLOY_ENVIRONMENT:
    value: "staging"  # Deploy to staging by default
    description: "The deployment target. Change this variable to 'canary' or 'production' if needed."

As a result you should see DEPLOY_ENVIRONMENT variable with 'staging' prefilled and proper description.
Check the documention for more info: Prefill variables in manual pipelines

I came here looking to be able to use conditional variables in my pipeline. It sounds like you want something a little more advanced, so I don't know if this answers your question but maybe it will help someone else. See this link or do this:

variables:
  RUN_LOAD_TEST:
    value: "false"
    description: "Set to true to run the load test"

This can be used globally or at a job level.

Related