What is the right way to update android manifest with xbuild and Jenkins

1.2k Views Asked by At

In our environment we are building xamarin.android project and would like to pass $(build_number) variable to Jenkins build. Unfortunately Jenkins is building the project as if nothing was passed to the build workflow.

I tried to use XmlPoke which works fine for windows and doesn't work on mac at all.

os: mac os x jenkins & xamarin are the latest stable version

Please suggest.

3

There are 3 best solutions below

0
Mando On BEST ANSWER

There is no default solution/plugin for it if you are building under Mac OS Host. You have to create your own script/tool with input parameters to update xml attributes to a given value. Then use it with shell exec task.

3
Slav On

According to this link, you can access environment build variables in csproj file using $(VAR) notation.

So, predefined Jenkins variables, such as BUILD_NUMBER should be available directly inside your project use $(BUILD_NUMBER), nothing extra required during invocation.

0
Hangger Steven On

I found a good solution from http://jonathanpeppers.com/Blog/xamarin-android-builds-in-jenkins

<Target Name="BeforeBuild" Condition=" '$(JENKINS)' == '1' ">
<XmlPoke XmlInputPath="Properties\AndroidManifest.xml" Namespaces="&lt;Namespace Prefix='android' Uri='http://schemas.android.com/apk/res/android' /&gt;" Query="manifest/@android:versionCode" Value="$(SVN_REVISION)" />
<XmlPoke XmlInputPath="Properties\AndroidManifest.xml" Namespaces="&lt;Namespace Prefix='android' Uri='http://schemas.android.com/apk/res/android' /&gt;" Query="manifest/@android:versionName" Value="2.0.$(SVN_REVISION)" />
</Target>

Use it in your .csproj file and don't forget to set 'JENKINS' as a global environment with a value of 1.