It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Bitbucket Pipelines: How to set a build number in Spring Boot's application.properties file

We have a Spring Boot application.

It has a source/resources/properties/application.properties file, which is a fallback/base properties for all environments. 

It contains the line:

app.buildNumber=%BITBUCKET_BUILD_NUMBER%

I have a set-build-number.sh script which runs before the Maven build, and basically does this:

PROP_FILE=$BITBUCKET_CLONE_DIR/platform/src/main/resources/application.properties

echo "Setting build number to: $BITBUCKET_BUILD_NUMBER in properties file: $PROP_FILE"

sed -i".original" -e "s/%BITBUCKET_BUILD_NUMBER%/$BITBUCKET_BUILD_NUMBER/g" $PROP_FILE
grep "app.buildNumber" $PROP_FILE

And in the build logs, I see the following:

+ ./scripts/set-build-number.sh

Setting build number to: 3795 in properties file: /opt/atlassian/pipelines/agent/build/platform/src/main/resources/application.properties

app.buildNumber=3795

So, everything looks fine so far.

However, when I look at value returned by the application (via REST API), it is still set to the original placeholder value.

What am I doing wrong?

Thanks.

2 answers

0 votes

Hi Chris,

Can you verify that the file has the build number correctly substituted with a cat command?

cat $PROP_FILE

Do you see if the placeholder value, or the desired build number?

If it's the placeholder then the substitution command will need updating.

If it's the correct build number, then where does the number get read from? Does it need to be committed back to the repository at any stage?

Thanks,

Phil

Hi Phillip,

Please see the property entry, bash script and output in my original post.

The following line is the output of the grep command above:

app.buildNumber=3795

So, the sed command is definitely working correctly.

My understanding was that the repo gets cloned (to a working directory), my property substitution would work off of that clone, and then the artifact gets built from that source and then deployed (we deploy to Heroku). 

If it's the correct build number, then where does the number get read from?

When the app runs, the build number gets read by our Spring Boot application from the application.properties file.

Does it need to be committed back to the repository at any stage?

That's my question for you guys. Does it require a commit? Am I misunderstanding the build process? (i.e. that working directory gets used to build the final artifact)

Thanks,

Chris

My understanding was that the repo gets cloned (to a working directory), my property substitution would work off of that clone, and then the artifact gets built from that source and then deployed (we deploy to Heroku).

You've got the right assumption here.

That's my question for you guys. Does it require a commit? Am I misunderstanding the build process? (i.e. that working directory gets used to build the final artifact)

In this case it doesn't sound like you need a commit.

Everything seems fine in your Pipelines configuration, as far as I can tell.

Does this work correctly if you do the same thing locally? (You can try use Docker to debug if you need)

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket Pipelines

What We Learned When We Researched Open Source Vulnerabilities in 7 Popular Coding Languages

...hey are a part of us, shaping how we interact with the world around us. The same holds true for programming languages when we think about how different kinds of vulnerabilities raise their heads in t...

1,042 views 0 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you