15

I am working on a pet project with Xamarin.Forms and am wondering if anyone has had experience with configuring gitlab-ci.yml builds successfully. There seems to be limited material on configuring for .NET builds in general, trying my luck at building one successfully before stringing together both builds. Have tried per-project .csproj for build path.

Any insight and experience would be appreciated.

Current .gitlab-ci.yml

image: mono

variables:
   Solution: Solution.sln

stages:
  - build
  - test
  - deploy

before_script:
  - nuget restore $Solution

build:
  stage: build
  script:
    - MONO_IOMAP=case xbuild /p:Configuration="Release" /p:Platform="iPhone" /t:Build $Solution
Saamer
  • 4,687
  • 1
  • 13
  • 55
Shazbot
  • 1,444
  • 1
  • 11
  • 21
  • Any success with it? – jzeferino Jun 29 '17 at 18:40
  • @jzeferino there’s an issue on the GitLab repo for .NET example that has a few examples in the comments. Nothing merged yet but some good starting points. https://gitlab.com/gitlab-org/gitlab-ci-yml/issues/12 – Shazbot Jun 29 '17 at 22:40
  • I will take a look but im planning to use cake with it. – jzeferino Jun 29 '17 at 22:41
  • 1
    There is a Cake example in there by @bravecobra that might help haha. – Shazbot Jun 29 '17 at 22:44
  • 1
    For Xamarin.Forms you either need windows or mac build agent, I don't think gitlab has any of them. You can use https://appcenter.ms it is free anyway. – Akash Kava Sep 10 '18 at 19:13

2 Answers2

5

Yes, we got it to work perfectly without needing to use boots or AzureDevops. As @AkashKava mentioned, I had to make it run on a Mac build agent/runner though, and I used AppCenter's CLI commands for the distribution part of it, where I also stored my certs, keystore and provisioning profiles.

So before everything runs, make sure you restore nuget packages and installs the necessary libraries nuget, msbuild, appcenter,...:

before_script:
  - nuget restore

Then, for creation of an Android QA apk file:

android_dev_apk:
  stage: build
  dependencies: []
  tags:
    - xamarin
  script:
    - msbuild {AppName}.sln $BUILD_VERBOSITY /t:Clean /p:Configuration=Dev
    - msbuild {AppName}.sln $BUILD_VERBOSITY /t:Build /p:Configuration=Dev
    - msbuild {AppName}.Android/{AppName}.Android.csproj $BUILD_VERBOSITY /t:PackageForAndroid /t:SignAndroidPackage /p:Configuration=Dev /p:AndroidKeyStore=True

Just replace {AppName} with your App's folder name/app name which was the same in my case. Similarly for iOS

ios_qa_app:
  stage: build
  dependencies: []
  tags:
   - xamarin
  script:
   - rm -rf {AppName}.iOS/bin/iPhone/QA
   - msbuild {AppName}.sln $BUILD_VERBOSITY /t:Clean /p:Platform=iPhone /p:Configuration=QA
   - msbuild {AppName}.sln $BUILD_VERBOSITY /t:Build /p:Platform=iPhone /p:ArchiveOnBuild=true /p:Configuration=QA
  artifacts:
    paths:
     - {AppName}.iOS/bin/iPhone/QA/{AppName}.ipa
     - {AppName}.iOS/bin/iPhone/QA/{AppName}.app.dSYM
    expire_in: 10 day
    when: on_success
  only:
    - schedules
  except:
    variables:
      - $ProdBuild == "true"

Note that under script, everything acts like it would when you use the Terminal, so you can also just type stuff like ls just to print the list of files in that folder in the output log, or cd .. or cd DirectoryName to change folders.

So to distribute the Android artifact, add this in your Android script:

    - appcenter distribute release --app {CompanyInAppCenter}/{AndroidAppNameInAppCenter} --group "Collaborators" --file {AppName}.Android/bin/QA/{BundleIdentifier}-Signed.apk --token=${APPCENTER_API_TOKEN}

Finally, to distribute the iOS artifact, add this in your iOS script:

    - appcenter distribute release --app {CompanyInAppCenter}/{iOSAppNameInAppCenter} --group "Collaborators" --file {AppName}.iOS/bin/iPhone/QA/{AppName}.ipa --token=${APPCENTER_API_TOKEN}

PS: I have written an article on how to do some of this stuff using GitHub Actions without using your own Build Agent.

Saamer
  • 4,687
  • 1
  • 13
  • 55
  • 1
    Thank you for your answer, Saamer! I haven't touched Xamarin in years and won't have a chance to verify myself but if anyone else does, please let me know and I'll mark accepted. – Shazbot Aug 04 '20 at 02:28
  • 1
    No worries @Shazbot! I was going through the oldest unanswered questions of Xamarin and found this. And realized that I did use GitLab for the CI/CD of Xamarin iOS and Android applications. So I thought I would share, especially since a lot of people seem to be looking for the answer :) – Saamer Aug 04 '20 at 14:54
-2

not yet, unfortunately you will need a windows machine, prerequisites :

  • Windows
    • Yeah! .NET Framework only works in Windows OS, so the machine you are going to use needs to be using Windows.
  • Git
    • Do you think we need Git installed? Alright, that’s a joke, it’s obvious we need git, by the way we are going to use GitLab!
  • MSBuild
    • To be able to build and publish our application, we need to have MSBuild installed.

You can get more information here on building on .Net which the new Xamarin forms depends on.

LeRoy
  • 4,189
  • 2
  • 35
  • 46