This is a guest post by Slava Chernikoff, Principal Engineer at Binwell.

Mobile DevOps falls under the umbrella of enterprise DevOps, since mobile applications are primarily a user interface for interacting with external IT systems. Mobile teams tend to have a much smaller scale, however, plus has its own unique challenges in multiple platforms and devices. You can find the high-level difference between mobile and enterprise applications in Figure 1.
 

 
Our focus in this blog is helping you setup a mobile CI/CD solution using Visual Studio App Center.

1. Mobile CI/CD Pipeline
Toolkits for building and publishing installation packages have been around for a long time. Typically, this is a set of scripts that is used on the build machine in the mobile development team. Figure 2 shows the general process of Mobile CI/CD. Recently however, cloud services have started to gain popularity for the implementation of CI/CD, which is where App Center comes into play.
 

1.1 Build Tools
You can run the CI/CD-pipeline either independently or via your enterprise collaboration tool command – in our case, Slack, or automatically for every push to the repository. With cloud CI/CD it is better to configure the automatic option, as this will shorten the way of receiving information about errors. Below are the necessary settings for the build pipeline in App Center (add the project in App Center, connect the code repository and configure Build for different branches - see Figure 3).
 

Manual mode is best left for more complex scenarios - for example, preparing a separate assembly for A/B testing, or running a wider set of functional tests before delivery to beta users.
 
In order to run test automation in App Center from your build configuration, you need to write bash-scripts for iOS/Android and put them in the project folder:

  • appcenter-post-clone.sh - starts right after the remote repository is cloned on the build-machine (mac for iOS/Android). You can run unit tests here:
  • appcenter-pre-build.sh - it is executed before the application build, here it is possible, for example, to write BUILD_ID in the application version (x.y.BUILD_ID);
  • appcenter-post-build.sh - starts immediately after the successful building of the application. At this step, you can run custom Smoke tests on real smartphones/tablets or advanced Acceptance or tests.

Since the building (including packaging and signing) of actual mobile applications takes quite a long time (more than 5-10 minutes), you can run unit-tests on post-clone or pre-build steps, this will allow quick diagnostics of key mechanisms. But Smoke testing, which is highly recommended in mobile development, should be done after the build. This will verify that the application, at least, will run on real smartphones with the required OS versions.

1.2 Cloud Build Machines 
In order to build applications in the App Center, virtual Macs working on Apple hardware are used. These machines have a rich set of tools that you can also use in your bash scripts - see Figure 4.
 

For more details on App Center Cloud Build Machines: https://docs.microsoft.com/en-us/appcenter/build/softwareand then we'll take a look at the scripts themselves.

1.3 Custom Scripts for Build Steps
If you have not written shell scripts for bash, then you need to practice a little and read the documentation: bing.com/search?q=bash+for+beginners
In our example, we created an automatic CI/CD pipeline for the master branch in the repository on GitHub: https://github.com/SlavaChernikoff/DevOpsXF.

As you can see in Figure 5, App Center automatically found our scripts that were added to the project folder (where the .xcodeproj, build.gradle, .csproj, .sln or package.json files are located).

When writing scripts, it may be necessary to use bash environment variables - an external script or the program writes its variable to the bash session, for example APPCENTER_SOURCE_DIRECTORY and this allows to use the value of this variable in your scripts. Key pre-defined environment variables in App Center:
 

Read more: docs.microsoft.com/en-us/appcenter/build/custom/variables You can also configure your environment variables in the build parameters (see Figure 7).

In your scripts, you can use the variables $MAJOR_VERSION and $MINOR_VERSION, as shown in the example for appcenter-pre-build.sh. In your scripts you can also modify your application source code with regular expressions and shell tools/commands.
 
Now let's look at each script separately. We'll start with the post-clone step, which will start Unit-tests. All examples are provided for Xamarin based Android project.
 
appcenter-post-clone.sh


 
As you can see, the script searches for folders with .csproj-files (Visual Studio projects), the name of which contains UnitTests and runs unit-tests based on NUnit or MSTest. In our example, unit-tests are implemented on with .NET Core and MSTest. You can use any familiar tools for unit-testing, depending on the framework which you will use to develop application.

appcenter-pre-build.sh
 

 
In this step, you can add BUILD_ID to the version of the application in the format MAJOR_VERSION.MINOR_VERSION.BUILD_ID. We can also perform any additional actions here before the build.

appcenter-post-build.sh
 

If the build has reached this step, then you have APK/IPA installation package. For many teams, the CI/CD pipeline was interrupted at this step, as it was required to check on actual devices, and on-premise device farms for UI-tests was a luxury. The provided script uses the App Center Test Cloud for automatic custom Smoke tests (based on Xamarin.UITest) to run the application. More details about automatic testing will be covered in the next article.

2. Automatic Testing as Part of Mobile CI/CD
As we mentioned earlier, mobile development has 3 distinct problem areas:
• Different screen resolutions of devices. Regardless of the number of pixels or aspect ratio, the application interface should be correctly displayed on all devices.
• Different operation systems and their versions. The application should work correctly on a wide range of operation systems, each of them has its own features and limitations.
• Different CPU architectures. The smartphones and tablets themselves are constantly improving, but we should not forget about the older devices produced five years ago, which can still be in use by the actual users.
 
However, part of the code can be easily covered by automatic tests based on Unit Testing tools. Let's look at the typical architecture of mobile application - Figure 8.
 

Full tests coverage is more reasonable to carry out in 2 directions:
• unit-tests (functional, integration) for a Data Access Layer (or Repositories).
• UI-tests (functional, regression) for Business Logic and User Interface layers.
Covering all layers of mobile application with Unit Tests is not possible, and it also reduces the speed of development. More details on automatic testing, will be covered in future article, now it’s important to say that the automatic CI/CD pipeline can include Unit and UI tests with App Center Test.

Conclusion
The mobile CI/CD approach allows you to simplify and accelerate the process of creating a quality product. Cloud Mobile CI/CD pipeline based on App Center allows to “configure-and-forget” environment for build, test and distribute. In this article we explained mobile development pitfalls and how to avoid them with automation.
In my next post, I’ll focus on automatic testing (Unit and UI): Stay tuned!

About the author
Slava Chernikoff is Principal Engineer at Binwell, and is a Microsoft MVP and Xamarin Certified Developer. He is an experienced mobile cross-platform and native developer, an author of popular articles and guides about Mobile DevOps and Xamarin, and a regular conference speaker. He was previously was honored as Nokia Champion and Qt Certified Developer and is a Microsoft MVP and Xamarin Certified Developer.

Mobile CI/CD 101的更多相关文章

  1. CI Weekly #1 | 这份周刊,带你了解 CI/CD 、DevOps、自动化测试

    原文首次发布与 flow.ci Blog >> 链接,转载请联系:) 准备了很久,CI Weekly 第一期终于来了. CI Weekly 围绕『 软件工程效率提升』 进行一系列技术内容分 ...

  2. Jenkins 配置CI/CD任务

    本文演示如何通过Jenkins创建CI/CD任务,部署一整套微服务体系结构,并运行在之前搭建的mini云平台上. 如果是初始尝试实践,可能需要参考 快速搭建云原生架构的实践环境 和 Jhipster技 ...

  3. 自建Git服务Gogs和CI/CD服务Drone

    自建Git服务Gogs和CI/CD服务Drone 项目:https://gogs.io Gogs运行 docker run -d --name=gogs -p 10022:22 -p 10088:30 ...

  4. Azure Data Factory(三)集成 Azure Devops 实现CI/CD

    一,引言 由于上一节文章内容过长,无法分享Azure Data Factory 的持续集成,持续发布.今天将着重介绍一下在使用 Azure DevOps Pipeline 发布,自动进行持续集成,并且 ...

  5. Jenkins+GitLab+SonnarQube搭建CI/CD全流程

    1. CI/CD 1.1 CI - 持续集成 持续集成( Continuous integration , 简称 CI )指的是,频繁地(一天多次)将代码集成到主干.持续集成的目的就是让产品可以快速迭 ...

  6. 庐山真面目之十一微服务架构手把手教你搭建基于Jenkins的企业级CI/CD环境

    庐山真面目之十一微服务架构手把手教你搭建基于Jenkins的企业级CI/CD环境 一.介绍 说起微服务架构来,有一个环节是少不了的,那就是CI/CD持续集成的环境.当然,搭建CI/CD环境的工具很多, ...

  7. jenkins在aws eks中的CI/CD及slave

    本文档不讲解jenkins的基础用法,主要讲解配合k8s的插件,和pipeline的用途和k8s ci/cd的流程. 以及部署在k8s集群内和集群外的注意事项. 1.准备工作 以下在整个CI/CD流程 ...

  8. CI Weekly #8 | CI/CD 技能进阶路线

    在使用 flow.ci 进行持续集成的过程中,也许你会遇到一些小麻烦.最近我们整理了一些常见问题在 flow.ci 文档之 FAQ,希望对你有用.如果你遇到其他问题,也可以通过「在线消息」或去 Git ...

  9. CI Weekly #6 | 再谈 Docker / CI / CD 实践经验

    CI Weekly 围绕『 软件工程效率提升』 进行一系列技术内容分享,包括国内外持续集成.持续交付,持续部署.自动化测试. DevOps 等实践教程.工具与资源,以及一些工程师文化相关的程序员 Ti ...

随机推荐

  1. 一致性Hash漫画图解

    一年之前—— 未来两年内,系统预估的总订单数量可达一亿条左右. 按Mysql单表存储500万条记录来算,暂时不必分库,单库30个分表是比较合适的水平分表方案. 于是小灰设计了这样的分表逻辑: 订单表创 ...

  2. 回顾曾经的自己,献给java初学者的建议

    要不惜代价投资自己,任何对自己的投资都是值得的 要多学习数据结构, 习惯看源码! 一份知识经过n个人的传递早已经不成样子了 遇到问题不要直接百度,百度上那些花里胡哨的东西有用的很少,对症下药才是王道, ...

  3. 对HTML5标签的认识(三)

    这篇随笔继续来认识HTML标签.这次随笔主要是对<table>标签的认识和最近我学习到的一些标签来和大家分享. 一.<table>标签 <table>标签的作用主要 ...

  4. react 脚手架 立即可以写业务 react + react-router-dom + less + axios + antd

    https://github.com/cynthiawupore/wq-cli

  5. 利用data-src属性 更换图片

    <div class="img_src"> <img src="./images/luo.png"></div> <u ...

  6. 【Android】用Cubism 2制作自己的Live2D——android sdk样本的下载与Android studio编译!

    前言- 在浏览Live2d说明书的时候我无意中发现了一个有趣的东西,就是android sdk中居然自带动态壁纸!那就让我们来试试吧,说明书此页的网址连接——中文版||日文版 Android开发所必需 ...

  7. Numpy库的学习(五)

    今天继续学习一下Numpy库,废话不多说,整起走 先说下Numpy中,经常会犯错的地方,就是数据的复制 这个问题不仅仅是在numpy中有,其他地方也同样会出现 import numpy as np a ...

  8. base64图片存储

    将图片转换为Base64编码,可以让你很方便地在没有上传文件的条件下将图片插入其它的网页.编辑器中. 这对于一些小的图片是极为方便的,因为你不需要再去寻找一个保存图片的地方. Base64编码在ora ...

  9. 大整数相乘问题总结以及Java实现

    最近在跟coursera上斯坦福大学的算法专项课,其中开篇提到了两个整数相乘的问题,其中最简单的方法就是模拟我们小学的整数乘法,可想而知这不是比较好的算法,这门课可以说非常棒,带领我们不断探索更优的算 ...

  10. 使用Log4Net进行错误日志记录

    http://blog.csdn.net/zdw_wym/article/details/48802821