I defined a repository variable :
Then I tried using it in my pipeline to pass it to sonarcloud :
But it seems empty. Echo returns nothing and sonar fails because the variable is not set :
From the documentation, echo $SONAR_TOKEN should write $SONAR_TOKEN in the console because it is a secured variable. It writes nothing.
I think it was because of the windows runner.
It is not very clear in the documentation whether repository variables are supported by windows runners or not, either way I find windows runners too restrictive (no pipes, no services...) so I switched to the Bitbucket cloud infrastructure to run my pipelines. It's a lot better and I didn't have any more issue with environment variables.
tl;dr : Windows runners suck and it's probably why my repository variables were empty
Hey @[deleted] ,
Repository variables are indeed supported on Windows runners, but since the runner is executed directly in Powershell, you will need to use Window's syntax to reference the variable.
Following is an example of how to print the value of a variable named My_Variable in a Windows environment :
$env:My_Variable
You can try using that syntax and the variable should be correctly printed in the output (unless it's a secured variable, where its value will be masked).
We also have the following article that explains the difference in the syntax :
Thank you, @[deleted] !
Patrik S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Patrik,
Thanks for correcting me!
I didn't find this article in my search, thanks for pointing it out. Now that I have the answer, I even found one example in the windows runner documentation in SSH keys configuration. I think it could be more explicit though, environment variables are a common feature when using pipelines, and it can be confusing when every piece of documentation we can find is for linux with linux style variables.
I'm staying on the Bitbucket infrastructure for now, as I still find windows runners too limited, but this can help future windows users.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you try this with a non-secured variable, is that printed correctly to the log?
I am asking it, because secured variables are masked out in the logs by design! So, even if you can't see them in the echo's output, they should work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Aron, thanks for responding.
I tried adding a non-secured variable and echo it the same way, it still prints nothing.
Anyway, from what I understood, secure variables should display their name instead of there value in logs. Here it displays nothing and it seems to be empty when I give it to sonar.
I don't know if it's relevant but I'm using a self-hosted windows runner
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.