Displaying the drop-down list of values of a global variable based on the branch name selected in GitLab CI pipeline

Hi,

The global variables: section of my .gitlab-ci.yml file has a variable HOST_NAME with a list of values in options: as showing below:

variables:
  HOST_NAME:
    description: Select a host name to deploy
    value: web-dev-01
    options:
      - web-dev-01
      - web-dev-02
      - web-dev-03
      - web-prod-01
      - web-prod-02
      - web-prod-03

deploy:
  stage: deploy
  script:
    - echo "Deploying $HOST_NAME"

Now, when I run the pipeline, the HOST_NAME variable shows the default value web-dev-01 and other 6 server names become available in the drop-down list of this variable, whichever branch I run from.

I’d like to make the values available like below:

  • When running from dev branch, the default value of the HOST_NAME should show web-dev-01 and drop-down should show the first 3 server names (ending with dev-xx).

  • When running from master branch, the default value of the HOST_NAME should show web-prod-01 and drop-down should show the last 3 server names (ending with prod-xx).

Is it possible? If so, would you please show how?

Modify the variables entries in each Git branch. This will create a diverging Git history though for dev and master and can lead to merge commits or conflicts when dev gets merged to master for example.

Hi @dnsmichi - Thank you for the suggestion. The master branch of this repo gets code updates usually through merge requests from dev. Also, having different code base in different branches is not something we can maintain.

I’m pretty new in GitLab CI. Can you think about any other alternative like HTML we use in Jenkins?