Jammer
Jammer

Reputation: 10208

Azure Pipeline - Automating Android Version Code

I picked up a project that had been managed by another team and the last released version use a version code of 5034.

They had been pushing these out from a developers machine directly rather than using a formal build process.

In my build script I have a manifest versioning step defined as:

- task: android-manifest-version@1
  displayName: 'Set Android version numbers'
  inputs: 
    sourcePath: '$(androidManifestPath)'
    versionCodeOption: 'buildid'
    versionCode: $(Build.BuildId)
    versionName: $(baseVersion).$(Build.BuildId)
    printFile: true

But our buildId is at a much lower number (4444) at the moment.

Looking over the available variables here, nothing seems to be jumping out as a solution.

I suppose I could just set this to a value manually in the build script but that feels a little dirty.

Is there a simple solution I'm overlooking?

UPDATE

I'm wondering if I could use something like this:

Create a new variable in my custom shared-variables.yml like:

versionCodePrefix: '600'

And then in the scripts use this

versionCode: $(versionCodePrefix)$(Rev:r)

UPDATE2

I've just found this option for the build step:

versionCodeOption: 'timestamp'

Inserts a unix format time stamp. Going to try this approach.

Upvotes: 2

Views: 3468

Answers (1)

Jammer
Jammer

Reputation: 10208

So it turns out the versioning plugin has a few options I'd not investigated.

My final yml task looks like this:

task: android-manifest-version@1
  displayName: 'Set Android version numbers'
  inputs: 
    sourcePath: '$(androidManifestPath)'
    versionCodeOption: 'buildid'
    versionCode: $(Build.BuildId)
    versionCodeOffset: '1000'
    versionName: $(baseVersion).$(Build.BuildId)
    printFile: true

Keeping it all automated but by using the versionCodeOffset value it combines by adding the two integer values together. So a build version of 2.0.4448 will result in a versionCode of 5448.

Upvotes: 3

Related Questions