Skip to content

Environment variable to create a file

Description

We have project integrations that are pretty cool: you can enter in a few parameters and we'll turn them into useful variables to be consumed by CI/CD pipelines. Integrations can also do other things, but many times they're just wrappers for variables. That said, they have some downsides.. for example there can only be one of each type for a given project, and we had to move Kubernetes out of service integrations into their own page because of this. If we consider adding an AWS integration, we'd face the same challenge. Also, variables support "protection" so that their values are only present when used with protected branches. Wouldn't it be nice if the service integrations had those same capabilities? Well, rather than building in environment and protected filtering, what if we turned things around and just put the power into variables themselves.

This approach simplifies both the user experience as well as the back-end implementation. The existing service integration code is considered technical debt that we are looking to remove, and this facilitates that effort.

Proposal

As MVC, we will create a "file" special variable type which creates a file in the runner build folder.

  • Add a type to variables. Default variables would be key-value pairs, just like it works today.
  • Allow users to set a variable name (key) and content (value) to the File variable.
  • This will result in a file with a random filename created. The path to the file will be placed in the environment variable, and the contents of the file will be filled with the value.

Further thoughts

This is expanded on next by creating an integration in this way, for AWS: https://gitlab.com/gitlab-org/gitlab-ce/issues/57780. The next iteration will prove out interesting features like validating the content of the variables in some interesting way.

UX Proposal

What's new:

  1. To improve usability, added labels on top of each input field to indicate what they represent in the 'Environments variables' section.
  2. Added Type dropdown button. User should be able to enter select the variable type.
Prototype
MVC-2-default__2_
**Under the Environments variables section on project Settings:**

- User sees a dropdown with the option to select a variable type. The dropdown displays two options: Variable (default set of predefined variables), and File.
- The form should start with the Variable option selected. It is reasonable to use it as default, as on entering the page the user sees the default variable input fields.
- User should be able to add/remove text from the input fields.
- The general interaction for the page still applies. Entering any data in the fields, or pressing return/enter while one of the form field items is selected should create a new row on the page.

Links / references

Edited by Jason Yavorsky