在上篇博客[Cake] 1. CI中的Cake中介绍了如何在CI中利用Cake来保持与CI/CD环境的解耦。

1. 简化cake的安装

当时dotnet 2.1还未正式发布,dotnet 还没有工具的支持,使得安装cake非常麻烦。不过随着 dotnet tool 的加入,这一问题得到了很好的解决。目前安装cake(0.30.0版本之后)只需要一行命令即可:

 dotnet tool install -g cake.tool

然后就可以使用cake了。用 dotnet cake 或者 dotnet-cake 都可以,推荐使用前者。

 $ dotnet cake --help

 Usage: Cake.exe [script] [--verbosity=value]
[--showdescription] [--dryrun] [..] Example: Cake.exe
Example: Cake.exe build.cake --verbosity=quiet
Example: Cake.exe build.cake --showdescription Options:
--verbosity=value Specifies the amount of information to be displayed.
(Quiet, Minimal, Normal, Verbose, Diagnostic)
--debug Performs a debug.
--showdescription Shows description about tasks.
--showtree Shows the task dependency tree.
--dryrun Performs a dry run.
--exclusive Execute a single task without any dependencies.
--bootstrap Download/install modules defined by #module directives
--version Displays version information.
--info Displays additional information about Cake execution.
--help Displays usage information.

2. 简化cake的引导脚本

上一篇博客[Cake] 1. CI中的Cake中出现的cake的引导脚本 build.ps1 和 build.sh ,绝大部分代码都是在下载安装cake用的,既然有了上面的 dotnet tool 命令可以安装cake,那么当然也就可以简化一下了。

引导脚本中包含安装和执行命令的代码。nuget相关的环境变量是项目需要的,cake脚本可以读取这些信息来使用。

2.1 cake.ps1

 [string]$SCRIPT       = '0-build/build.cake'
[string]$CAKE_VERSION = '0.33.0' # nuget server config
$ENV:NUGET_REPOSITORY_API_URL = "http://nuget-server.test/nuget"
$ENV:NUGET_REPOSITORY_API_KEY = "" # Install cake.tool
dotnet tool install --global cake.tool --version $CAKE_VERSION # Start Cake
[string]$CAKE_ARGS = "-verbosity=diagnostic" Write-Host "dotnet cake $SCRIPT $CAKE_ARGS $ARGS" -ForegroundColor GREEN dotnet cake $SCRIPT $CAKE_ARGS $ARGS

查看一下cake脚本都有哪些task:

 $ .\cake.ps1 --showtree
Tool 'cake.tool' is already installed.
dotnet cake 0-build/build.cake -verbosity=diagnostic --showtree .... default
└─test
└─build
├─clean
└─restore push
└─pack
└─test
└─build
├─clean
└─restore

2.2 cake.sh

 #!/bin/sh

 SCRIPT='0-build/build.cake'
CAKE_VERSION='0.33.0' # nuget server config
export NUGET_REPOSITORY_API_URL='http://nuget-server.test/nuget'
export NUGET_REPOSITORY_API_KEY='' # Install cake.tool
dotnet tool install --global cake.tool --version $CAKE_VERSION
export PATH="$PATH:$HOME/.dotnet/tools" # Start Cake
CAKE_ARGS="$SCRIPT -verbosity=diagnostic" echo "\033[32mdotnet cake $CAKE_ARGS $@" dotnet cake $CAKE_ARGS "$@"

3. CI/CD

CI/CD的yaml配置文件不用做调整,只需执行对 cake.sh 或者 cake.ps1 的调用即可。这也是cake带来的避免在CI/CD中编程的好处,所有的逻辑都位于cake脚本中。

参考

dotnet tool https://docs.microsoft.com/zh-cn/dotnet/core/tools/dotnet-tool-install

cake 示例项目 https://github.com/linianhui/cake.example

[Cake] 2. dotnet 全局工具 cake的更多相关文章

  1. [Cake] 3. dotnet 本地工具 cake & dotnet format

    在上一篇[Cake] 2. dotnet 全局工具 cake中介绍了通过.Net Core 2.1 的全局工具dotnet tool命令来简化cake的安装和使用.因为是全局安装,则无法适应每个项目对 ...

  2. .net core下的dotnet全局工具

    .net core 2.1后支持了一个全新的部署和扩展命令,可以自己注册全局命令行. dotnet install tool -g dotnetsaydotnetsay 也可以自己构建自己的命令行,一 ...

  3. [Cake] 1. CI中的Cake

    在上一篇C#Make自动化构建-简介中,简单的介绍了下Cake的脚本如何编写以及通过Powershell在本地运行Cake脚本.本篇在此基础上,介绍下如何在CI环境中使用Cake. 1. Cake简介 ...

  4. 使用 .NET Core CLI 创建 .NET Core 全局工具

    https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=2&ch=&tn=baiduhome_pg& ...

  5. 【Devops】【docker】【CI/CD】docker启动的Jenkins容器 - 系统管理 - 全局工具配置 - 自动安装JDK、Maven、Git、Docker

    本篇适用于jenkins是启动的docker容器,自动安装JDK  Maven  Git   Docker等全局工具 ========================================= ...

  6. dotnet CLI工具是如何运行你的代码的

    原文连接:https://mattwarren.org/2016/07/04/How-the-dotnet-CLI-tooling-runs-your-code/作者 Matt Warren.授权翻译 ...

  7. yii学习笔记(3),自定义全局工具函数

    在平时开发是经常需要打印数据来调试 常见的打印方式有print_r和var_dump,但是这样打印出来格式很乱不好浏览 在打印函数前后加上<pre></pre>就可以将内容原样 ...

  8. Android 写一个Activity之间来回跳转的全局工具类(主要是想实现代码的复用)

    废话不多说了,直接上代码,相信大家都能看得懂的. 一.主要工具类 package com.yw.chat.utils; import android.app.Activity; import andr ...

  9. DotNet.Utilities工具类

    来源:http://git.oschina.net/kuiyu/dotnetcodes/tree/master/DotNet.Utilities

随机推荐

  1. 基于名称的虚拟主机-Apache

    基于名称的虚拟主机和基于IP的虚拟主机的对比 基于IP的虚拟主机使用连接的IP地址来识别(区分)正确的虚拟主机,所以对于每一个虚拟主机,你都需要有独立的IP地址. 基于名称的虚拟主机,服务器依赖于客户 ...

  2. 关于dataTable 生成JSON 树

    背景: POSTGRESL + C#  + DHTMLX SUIT 一个表生成一个JSON串,这个不是很麻烦: 1.在数据库(postges)中:  json_agg(row_to_json(t)) ...

  3. Object-C反射读取实体属性和值

    举例: 首先定义TestModel如下: @interface TestModel : NSObject @property (nonatomic, strong) NSString *name; @ ...

  4. JVM的内存划分

    1.栈内存:栈内存主要是用来运行函数的,在函数中定义的所有变量,都会在这个内存开辟空间. 在栈内存中定义的变量,不初始化,是不能直接使用的. 注意:所有的函数都必须在栈内存中运行. 而jvm只会运行处 ...

  5. jsp四大作用域之request

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  6. jsp跳转标签<jsp:forward>

    forward.jsp <%@ page language="java" contentType="text/html; charset=utf-8" p ...

  7. UVA 147 Dollars 刀了(完全背包,精度问题)

    题意:一样是求钱的转换方案数,但是这次单位下降到分,但给的是元为单位的,所以是浮点的,但是固定有两位小数. 思路:数据都放大100倍来计算,去除精度问题,转成整型时要注意精度.即使给的是0.02,乘以 ...

  8. BZOJ 4242: 水壶 Kruskal+BFS

    4242: 水壶 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 427  Solved: 112[Submit][Status][Discuss] D ...

  9. linux概念和体系

    1. Linux开机启动 2. Linux文件管理 3. Linux的架构 4. Linux命令行与命令 5. Linux文件管理相关命令 6. Linux文本流 7. Linux进程基础 8. Li ...

  10. Eclipse中添加MyEclipse插件

    下载准备: 下载myeclipse7.0:http://downloads.myeclipseide.com/downloads/products/eworkbench/7.0M1/MyEclipse ...