Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Repository variables are empty

Deleted user June 7, 2023

I defined a repository variable :

Capture d'écran 2023-06-07 143222.png

Then I tried using it in my pipeline to pass it to sonarcloud :

Capture d'écran 2023-06-07 143818.png

But it seems empty. Echo returns nothing and sonar fails because the variable is not set :

Capture d'écran 2023-06-07 144231.pngCapture d'écran 2023-06-07 144302.png

From the documentation, echo $SONAR_TOKEN should write $SONAR_TOKEN in the console because it is a secured variable. It writes nothing.

2 answers

1 accepted

1 vote
Answer accepted
Deleted user June 8, 2023

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

Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 8, 2023

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

Deleted user June 9, 2023

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.

0 votes
Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 7, 2023

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.

Deleted user June 8, 2023

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events