glab icon indicating copy to clipboard operation
glab copied to clipboard

reading CI variable from CLI

Open mkjmdski opened this issue 4 years ago • 6 comments

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

mkjmdski avatar Sep 14 '21 08:09 mkjmdski

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

profclems avatar Sep 17 '21 10:09 profclems

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

profclems avatar Sep 17 '21 10:09 profclems

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?

mkjmdski avatar Sep 17 '21 21:09 mkjmdski

Or to some other part of glab help sections, kind of the same way that using GraphQL is described inside glab 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.

profclems avatar Sep 17 '21 21:09 profclems

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.

clemsbot avatar Nov 06 '21 02:11 clemsbot

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!

cj13579 avatar Jan 06 '22 20:01 cj13579