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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,466,652
Community Members
 
Community Events
176
Community Groups

Repository variables and property files

Hi all,

I'm currently using a BitBucket pipeline to run a Maven / Java JUnit tests to exercise a REST API. This runs fine, but it requires a username and password which is currently written in a property file.  I want to move the values from the property file and into some respository variables, but retaining the property files.

I've configured the respository variables and and I can access them in my pipleline script using $VARIABLE_NAME, etc.

However, I don't know if its possible, but can I also use the same repository variables in my property files which my Java program reads when starting?

For example, I have property file called database.properties with some configuration and inserted the respository variables like this:

database.server=${DATABASE_SERVER}

database.username=${DATABASE_USERNAME}

database.password=${DATABASE_PASSWORD}

somevalue=${VARIABLE_NAME}

When I run the pipleline, the variables are read fine in the bitbucket-pipeline.yml file,  but when the program runs there are no values in the property file.  Is there some additional processing of the properties file required?

Any help or advice is appreciated.

Kind regards,
David

 

 

1 answer

0 votes
Patrik S Atlassian Team Oct 25, 2021

Hello @David Smiles

Thank you for reaching out to Atlassian Community!

I've reviewed your case, and as per Variables and Secrets documentation, when your pipeline build starts, all the user-defined variables are configured as Environment Variables in the build container.

As you already confirmed, the commands and scripts invoked on the YML can use the variables by referencing them as $VARIABLE_NAME. However, each language handles/references environmental variables differently, and it's up to your program to interpret that. In your case, you can have your environment variables in the properties file, but Java will not automatically recognise them as environmental variables and therefore will not replace them with their actual values.

To help you proceed further, I have the following suggestions :

 

  • Write a function in your Java program that handles the environment variable substitution when you read the property file
  • Instead of reading from the property file, directly reference the variables in your Java program, as this example:
    • System.getenv("VARIABLE_NAME")

Hope that helps to address your question! Feel free to share any additional concerns with this case.

Best regards,

Patrik S

Atlassian Support Engineer

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events