reading CI variable from CLI
Describe the feature or problem you'd like to solve
It would be great if glab cli could read CI/CD variable same way as it is set
Propose a Solution
glab variable get <VAR_NAME> would read variable content
Additional context https://docs.gitlab.com/ee/api/project_level_variables.html API allows to do that
I decided to work on this but I couldn't agree on a better implementation. I don't know if it's a good idea to display the CI variables values in the terminal, especially for masked and/or protected variables
In the meantime, you can create your own command using the api and alias commands.
This is what I use:
glab alias set get-variable 'glab api /projects/:id/variables/$1 | jq .value' --shell
So I just do:
glab get-variable CODECOV_TOKEN
That's a lovely solution! Thank you, do you think it might make sense adding instructions on how to prepare that solution to the help section of glab variables? Or to some other part of glab help sections, kind of the same way that using GraphQL is described inside glab api?
Or to some other part of
glabhelp sections, kind of the same way that using GraphQL is described insideglab api?
Yeah makes sense. Thanks for bringing that up!
We need to add it to the help section of the glab api command. Most people don't know they can actually create their own commands with the api and alias command.
This issue has been automatically marked as stale because it has not had recent activity. We haven't had the time to address it yet, but we want to keep it open. This message is just a reminder for us to help triage issues.
Rather than open a new issue, I wonder if I can ask a related question here: Is it possible to set a variable for a pipeline via the same API/alias command combo (or via some other method entirely)? Its not obvious from the documentation on running pipelines that setting pipeline variables is possible.
Thanks!