https://novemberfive.co/blog/windows-jenkins-cake-tutorial/

Where we started, or: why Cake took the cake

Before we started using Cake to build our Windows 10 applications, we used a similar setup, but instead of Cake we used an MSBuild script.

What went wrong? Well, nothing! We could do everything what we wanted with the MSBuild script. In fact, the Cake build script does exactly the same thing our old MSBuild file took care of.

So why did we replace the MSBuild script with Cake?

The answer is pretty simple: MSBuild uses xml to configure the build task. Cake build scripts are written in C#. As C# developers we write C# code on a daily basis, which means Cake, unlike MSBuild, feels instantly familiar (and doesn’t have us researching syntax on a regular basis). This means writing and changing the build scripts is easier, quicker, and fewer mistakes are made. It also means that any developer can make these changes, without having to go through a learning curve first.

Some more advantages for us were the fact that we can make identical builds wherever we want with Cake (on our local machine, Jenkins, …) and the fact that it offers a Visual Studio Code plugin with syntax highlighting.

Our recipe: application lifecycle management via Git, Jenkins and Cake for UWP

So how does our solution work?

Jenkins fetches the changes from Git via polling; gets and commits any new translations from Phraseapp; and starts the default Cake task.

Cake can then:

  • clean the solution
  • take care of the semantic versioning, based on git branches
  • restore the nuget package
  • perform the actual build of the applications
  • run unit tests
  • create an app package bundle
  • sign the app package bundle

At this point, Jenkins kicks back into action. It archives the packages, in our case to Dropbox and to a dedicated server, and uploads the beta builds to Hockey app. It then notifies the developers and/or project manager via Slack when new builds are available or have failed.

Now, let’s get down to the details to help you get the same workflow!

Preparing your Cake

Step 1: Preparing Git

Only files necessary for building the application are checked in with Git. All other files, like binaries and helper files, are ignored. We do this via a gitignore. We have to ignore following folders: tools and build (a custom folder we created to temporarily store the build artifacts).

To do this, simply add the following lines to the gitignore file; you can place them anywhere in the file.

#Cake
build
tools

Step 2: Acquiring Cake

You can download Cake from the website, install via Powershell or use the Visual Code plugin to acquire it. You only need two files to start working with Cake. You can place these files anywhere in the repository, but we prefer to place them at the root.

  • build.ps1: The bootstrapper powershell script. This file downloads Cake and its dependencies when needed. It contains a basic configuration and will start Cake.
  • build.cake: This file contains our buildscript. It will have some basic configuration by default.

With these files in place, we can run Cake for the first time. To do so, start powershell with administrator rights. Go to the root of your repository, for example:

cd c:\projects\ExampleApp

Execute the bootstrapper script:

.\build.ps1

That’s it! You should now see something like this:

Step 3: Customizing the bootstrapper

In our company, we use three build types (build configurations in Visual Studio), which are aligned on all platforms:

  • Debug: For development only
  • Beta: For beta distribution and testing
  • Release: The actual store build

The bootstrapper file (build.ps1) supports only Debug and Release by default. To better suit our needs, we replaced [ValidateSet("Release", "Debug")] with [ValidateSet("Release", "Beta")].

Step 4: Making our Cake file

First, we clean up the solution and remove the old build artifacts, to make sure we start with a clean slate:

Task("Clean")
.Does(() =>
{
// Remove old build artifacts from the build output folder
CleanDirectories(projectPath + "/AppPackages"); // Clean the solution, uwp supports multiple platforms
foreach(var platform in supportedPlatforms)
{
MSBuild(solutionFile, configurator =>
configurator.SetConfiguration(buildConfiguration)
.SetVerbosity(Verbosity.Quiet)
.SetMSBuildPlatform(MSBuildPlatform.x86)
.SetPlatformTarget(platform)
.WithTarget("Clean"));
}
});

Next, we set up the semantic version of the app, using the GitVersion Tool. This version will be added in AssemblyInfo.cs. The GitVersion Tool is not part of the default Cake installation, so we have to add an import on top of the Cake.file:

#tool "nuget:?package=GitVersion.CommandLine"

Task("Versioning")
.IsDependentOn("Clean")
.Does(() =>
{
GitVersion(new GitVersionSettings {
UpdateAssemblyInfo = true
});
});

The next step is using a default command to restore the packages.

Task("NugetPackageRestore")
.IsDependentOn("Versioning")
.Does(() =>
{
NuGetRestore(solutionFile);
});

After this, we define the actual build. We do this multiple times, once for each platform.

Task("Build")
.IsDependentOn("NugetPackageRestore")
.Does(()=>{
foreach(var platform in supportedPlatforms)
{
MSBuild(solutionFile, configurator =>
configurator.SetConfiguration(buildConfiguration)
.SetVerbosity(Verbosity.Quiet)
.SetMSBuildPlatform(MSBuildPlatform.x86)
.SetPlatformTarget(platform)
.WithTarget("Build"));
}
});

After the build of the application, we run all our tests. In this example we run only unit tests. All the names of our unit test projects are ending with “.UnitTests”. We can use a wildcard to find all our test projects.

Task("Test")
.IsDependentOn("Build")
.Does(()=>{
MSTest("./Tests/**/*.UnitTests.dll");
});

As final step we sign the generated appxbundle. This is needed to install the app on Windows 10 mobile. If you want to install the app on a PC, just zip all files, because HockeyApp supports only one file for each app.

Task("Sign")
.IsDependentOn("Test")
.Does(()=>{ if (!buildConfiguration.Equals("Release"))
{
var appxBundles = GetFiles(projectPath + "/AppPackages/**/*.appxbundle"); Sign(appxBundles, new SignToolSignSettings {
TimeStampUri = new Uri("http://timestamp.digicert.com"),
CertPath = "certificate.pfx",
Password = "Password"
});
}
});

The full file should look like this:

Jenkins serving Cake: our recipe for Windows的更多相关文章

  1. Jenkins持续集成(上)-Windows下安装Jenkins

    环境:Windows 2008 R2.Jenkins2.235.1: 概要 前面写过一篇文章,<自动发布-asp.net自动发布.IIS站点自动发布(集成SLB.配置管理.Jenkins)> ...

  2. jenkins简单安装及配置(Windows环境)

    jenkins是一款跨平台的持续集成和持续交付.基于Java开发的开源软件,提供任务构建,持续集成监控的功能,可以使开发测试人员更方便的构建软件项目,提高工作效率. Windows平台下,一般安装方法 ...

  3. Jenkins的详细安装及使用--windows

    操作环境:Windows 一.环境准备 1 安装JDK 本文采用jdk-8u111-windows-x64.exe: 2 配置tomcat 本文采用tomcat8,无需安装,配置JAVA_HOME及J ...

  4. 微软开放技术发布开源 Jenkins 插件以将 Windows Azure Blob 服务用的开作存储库

     发布于 2014-02-10 作者 陈 忠岳 持续集成 (CI) 的历史源远流长, 其宗旨在于软件团队在敏捷环境中不断将他们的工作整合为持续构建.管理 CI 进程的工具已存在一段时间.过去几年中 ...

  5. NetBeans GUI tests on Jenkins + Windows (转)

    from http://forgetfulprogrammer.wordpress.com/tag/interact-with-desktop/ Running NetBeans applicatio ...

  6. 【最新】Android使用jenkins全自动构建打包-Windows版本(Android,Jenkins,360加固,Email,QRcode,参数构建,蒲公英)

    Android打包喝咖啡系列(Windows版) 这篇博客主要讲述的内容: 1.windows上部署Jenkins https://jenkins.io 2.基于SVN或Git https://git ...

  7. jenkins windows slave 构建c/c++代码

    关于如何再centos系统上的jenkins master下搭建windows系统的jenkins slave节点,本篇博客中不做介绍,如果有需要的话,请参考我的另外一篇博客,在其中介绍了不同系统的j ...

  8. Installing Jenkins as a Windows service

    Install Jenkins as a Windows service NOTE: if you installed Jenkins using the windows installer, you ...

  9. jenkins轻松玩玩远程windows的进程

    飞测说:在持续集成的路上走了小半年,遇到的一些问题,今天来说一个折腾好几天的问题,和大家交流.我们都知道C#语言开发的,部署站点在IIS上,但是用持续集成的时候,发现经常因为w3wp进程导致文件无法覆 ...

随机推荐

  1. 五 js对象简介

    对象简介 js中没有"类"的概念,只有对象. A:对象声明方式有三种 ------------1.调用Object函数创建对象: var person = new Object; ...

  2. 手动创建mfc工程(留存方便复制)

    案例一. #include <afxwin.h> class CMyWnd : public CWnd { //DECLARE_DYNCREATE(CMyWnd) public: CMyW ...

  3. 如何删除Sitecore CMS中的项目

    在此“如何”帖子中,我将介绍如何删除项目以及如何在Sitecore CMS中恢复已删除的项目. 删除项目 有多种方便的方法可以删除Sitecore中的项目. 从功能区 在内容树中选择您要删除的项目. ...

  4. uva 10600 ACM Contest And Blackout

    题意: 求最小生成树和次小生成树的总权值. 思路: 第一种做法,适用于规模较小的时候,prim算法进行的时候维护在树中两点之间路径中边的最大值,复杂度O(n^2),枚举边O(m),总复杂度O(n^2) ...

  5. 通过Hive将数据写入到ElasticSearch

    我在<使用Hive读取ElasticSearch中的数据>文章中介绍了如何使用Hive读取ElasticSearch中的数据,本文将接着上文继续介绍如何使用Hive将数据写入到Elasti ...

  6. 给定一个正整数,实现一个方法求出离该整数最近的大于自身的 换位数 <把一个整数各个数位进行全排列>

    """给定一个正整数,实现一个方法求出离该整数最近的大于自身的 换位数 -> 把一个整数各个数位进行全排列""" # 使用 permu ...

  7. HTTPS实战之单向验证和双向验证

    转载自:https://mp.weixin.qq.com/s/UiGEzXoCn3F66NRz_T9crA 原创: 涛哥 coding涛 6月9日 作者对https 解释的入目三分啊 (全文太长,太懒 ...

  8. webstorm实用快捷键

    webstorm实用快捷键 Ctrl+/ 或 Ctrl+Shift+/ 注释(// 或者/*…*/ ) Shift+F6 重构-重命名 Ctrl+X 删除行 Ctrl+D 复制行 Ctrl+G 查找行 ...

  9. SOAPUI 案例操作步骤

    1. 构建项目 2. 运行单个请求 3. 构建测试用例 4. 接口之间传递参数 5. 运行整个测试用例 构建测试 以天气接口为例: 接口: http://ws.webxml.com.cn/WebSer ...

  10. mybatis之关联映射

    ###mybatis使用之一对一关联映射 1)分析并画ER图.(特别是一对一.一对多.多对多的情况) 2)启动终端数据库,并建库建表,在表中插入值和字段,并查看结果.(后期把navicat用上) 3) ...