feat(ci): add support for job variables in CI trigger command

Description

This merge request adds support for job variables when triggering CI jobs via the glab ci trigger command.

Changes include:

  • Added --variables flag: Pass environment variables to job in format <key>:<value>
  • Added --variables-env flag: Pass environment variables to job in format <key>:<value>
  • Added --variables-file flag: Pass file contents as a file variable to job in format <key>:<filename>
  • Added -f, --variables-from flag: Load variables from a JSON file with array of hashes containing 'key' and 'value' fields

Implementation details:

  • Added helper functions: parseVarArg(), extractEnvVar(), extractFileVar(), and resolveJobVars() to parse and handle variable arguments
  • Updated NewCmdTrigger() to accept the new flags and construct JobVariablesAttributes options
  • Updated documentation with usage examples showing how to pass variables
  • All flags support multiple values (can be used multiple times)

Resolves #8005

How has this been tested?

This has been tested locally. Comprehensive unit tests have been added including:

  • Test for triggering with a single variable
  • Test for triggering with multiple variables
  • Test for triggering with --variables-env flag
  • Test for invalid variable format error handling
Edited by Swapnaneel Patra

Merge request reports

Loading