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. js事件循环机制辨析

     对于新接触js语言的人来说,最令人困惑的大概就是事件循环机制了.最开始这也困惑了我好久,花了我几个月时间通过书本,打代码,查阅资料不停地渐进地理解他.接下来我想要和大家分享一下,虽然可能有些许错误的 ...

  2. Cookie浅析

    Cookie  翻阅了好久关于Cookie的博客及文档,感觉一直有一块结没有解开,所以一直难以在脑中形成一个顺畅的知识脉络.最后实在是遭不住,拉上我的大神朋友在食堂里坐了3个小时,问了个底朝天!总算形 ...

  3. Spring Boot 2.x(十一):AOP实战--打印接口日志

    接口日志有啥用 在我们日常的开发过程中,我们可以通过接口日志去查看这个接口的一些详细信息.比如客户端的IP,客户端的类型,响应的时间,请求的类型,请求的接口方法等等,我们可以对这些数据进行统计分析,提 ...

  4. 微信公众号签名错误 invalid signature

    在出现了 invalid signature签名错误后按照以下步骤进行校验1.确认签名算法正确,可用 http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=j ...

  5. sql 服务启动失败 SQL Server(MSSQLSERVER) 错误码126

    SQL配置管理器-->sql server 网络配置-->mssqlerver的协议-->VIA禁用服务

  6. HTML/CSS快速入门

    Web概念 JavaWeb 使用java语言开发基于互联网的项目 软件架构 C/S架构:Client/Server 客户端/服务器 用户本地有一个客户端程序,在远程有一个服务端程序 如QQ,英雄联盟. ...

  7. 【视频】设计模式(Java)视频讲解

    设计模式(JAVA) 视频网址: http://www.qghkt.com/ 设计模式(JAVA)视频地址: https://ke.qq.com/course/318643?tuin=a508ea62 ...

  8. SQLServer修改登陆账户信息

    修改登陆账户信息注意事项 如果 CHECK_POLICY设置为ON,则无法使用 HASHED参数. 如果 CHECK_POLICY更改为ON,则将出现以下行为: 用当前的密码哈希值初始化密码历史记录. ...

  9. SQL Server数据库————模糊查询和聚合函数

    ***********模糊查询*********/ 关键字: like (!!!!字符串类型) in (,,)  匹配()内的某个具体值(括号里可以写多个值) between... and.. 在某两 ...

  10. 使用git提交代码到github,每次都要输入用户名和密码的解决方法

    自从使用git提交代码到github后,发现自己使用git的功力增长了不少,但也遇到不少问题.比如,使用git提交代码到github的时候,经常要求输入用户名和密码,类似这种: 网上有这么一种解决方法 ...