Search code examples
gitmavendeploymentbuildibm-cloud

Bluemix Retrieving Build Number in Deploy Stage


I've been tinkering around with Bluemix' Build and Deploy stages to track the build.

Simple enough question, how do I get the Build Number of the build sent to the Deploy stage of Build & Deploy within IBM Bluemix?

I have tried using $BUILD_NUMBER detailed here but this isn't working correctly for me within the Deploy stage

I'll show you what is happening..

Build Stage

Within the build stage I modify the POM file for my Maven Project to set the version to match the build.

echo 'Changing POM Version'
mvn --batch-mode release:update-versions -DdevelopmentVersion=0.0.${BUILD_NUMBER}-SNAPSHOT

I know that this works because I use this later on to also tag my git repository and both the POM and tag show the correct Build Number

enter image description here

This also means that the resulting jar from the build stage is StudyPlanner-0.0.41-SNAPSHOT.jar

Deploy Stage

The issue comes about when trying to use this same BUILD_NUMBER when retrieving the jar file for the deployment stage.

cf push "${CF_APP}" -p StudyPlanner-0.0.${BUILD_NUMBER}-SNAPSHOT.jar -b java_buildpack

The stage fails I receive the following error:

FAILED
Error uploading application.
lstat /home/pipeline/40d5622e-05a8-4d9f-a6ca-f8879bf48435/StudyPlanner-0.0.28-SNAPSHOT.jar: no such file or directory

As you can see, the deploy stage is trying to retrieve 0.0.28, rather than 0.0.41 as it should be in this instance.

To prove that it is build 41 which is being sent in to the stage here is a screenshot:enter image description here

Any guidance of why this $BUILD_NUMBER is picking up an old number, or on a better way to achieve getting the number within the deploy stage would be much appreciated.

Many Thanks,

Scott.

--------------------- UPDATE ---------------------

I have tried running this a few more times to see if I could find any patterns ect and found out the following:

During the Build stage, the $BUILD_NUMBER property refers to the number of times the Build stage has been ran.

During the Deploy stage, the $BUILD_NUMBER property refers to the number of times the Deploy stage has been ran.

Though the name $BUILD_NUMBER seems misleading, on re-reading the Bluemix Environment Variables documentation it states that this ID is incremental to the stage, rather than to the number of builds.

The incremental stage ID that is shown in the pipeline UI.

With this being the case, I now understand why $BUILD_NUMBER is giving me the "wrong" result, but I still do not know how I can achieve retrieving the build number within the Deploy stage.

Is there a way to set a variable or property within one stage to access in the next?


Solution

  • You can find a list of available environment variables here. The $BUILD_NUMBER is a bit confusing at it corresponds to the number of the job that is currently running. If you want the number of the build that is being used as input, you should use $IDS_VERSION. It is not in the doc mentioned above, but it will be the number you want. I will submit a pull request to update the docs.