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. Python:鲜为人知的功能特性(下)

    GitHub 上有一个名为<What the f*ck Python!>的项目,这个有趣的项目意在收集 Python 中那些难以理解和反人类直觉的例子以及鲜为人知的功能特性,并尝试讨论这些 ...

  2. Spring异常分析

    异常报错 2019-01-14 10:40:18.427 ERROR 11776 --- [ost-startStop-1] o.s.b.w.e.t.TomcatStarter : Error sta ...

  3. void类型和void* 的用法

    C语言中的void  和 void * 总结 1.void的作用 c语言中,void为“不确定类型”,不可以用void来声明变量.如:void a = 10:如果出现这样语句编译器会报错:variab ...

  4. DRDS分布式SQL引擎—执行计划介绍

    摘要: 本文着重介绍 DRDS 执行计划中各个操作符的含义,以便用户通过查询计划了解 SQL 执行流程,从而有针对性的调优 SQL. DRDS分布式SQL引擎 — 执行计划介绍 前言 数据库系统中,执 ...

  5. 零基础学Python--------第11章 使用Python操作数据库

    第11章 使用Python操作数据库 11.1 数据库编程接口 在项目开发中,数据库应用必不可少.虽然数据库的种类有很多,如SQLite.MySQL.Oracle等,但是它们的功能基本都是一样的,为了 ...

  6. IntelliJ IDEA下的使用git

    1.git简介 git是目前流行的分布式版本管理系统.它拥有两套版本库,本地库和远程库,在不进行合并和删除之类的操作时这两套版本库互不影响.也因此其近乎所有的操作都是本地执行,所以在断网的情况下任然可 ...

  7. Unity 2D 效应器与来回移动的实现

    1.效应器 Point Effector 2D: 点效应器.进入区域,吸引或排斥物体 Area Effector 2D: 区域效应器,可以用来做马里奥的管道移动效果 Surface Effector ...

  8. MySQL 基础知识梳理学习(七)----sync_binlog

    一般在生产环境中,很少用MySQL单实例来支撑业务,大部分的MySQL应用都是采用搭建集群的方法.搭建MySQL集群,可以进行数据库层面的读写分离.负载均衡或数据备份.基于MySQL原生的Replic ...

  9. MongoDB中数组类型相关的操作

    概述 在MongoDB的模式中,我们经常将一些数据存储到数组类型中,即我们常见的嵌套模式设计的一种实现方式.数组的这种设计实现方式在关系数据库中是没有或者说不常见的.所以,通过本文我们来梳理一下Mon ...

  10. Extjs renderer函数

    昨天提到了改变grid中 行的背景颜色,其实还有一个更简单的方法,就是利用renderer:function(){}函数 renderer 函数是一个拦截者模式,用于改变渲染到单元格的值和样式. re ...