[Cake] 2. dotnet 全局工具 cake
在上篇博客[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的更多相关文章
- [Cake] 3. dotnet 本地工具 cake & dotnet format
在上一篇[Cake] 2. dotnet 全局工具 cake中介绍了通过.Net Core 2.1 的全局工具dotnet tool命令来简化cake的安装和使用.因为是全局安装,则无法适应每个项目对 ...
- .net core下的dotnet全局工具
.net core 2.1后支持了一个全新的部署和扩展命令,可以自己注册全局命令行. dotnet install tool -g dotnetsaydotnetsay 也可以自己构建自己的命令行,一 ...
- [Cake] 1. CI中的Cake
在上一篇C#Make自动化构建-简介中,简单的介绍了下Cake的脚本如何编写以及通过Powershell在本地运行Cake脚本.本篇在此基础上,介绍下如何在CI环境中使用Cake. 1. Cake简介 ...
- 使用 .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& ...
- 【Devops】【docker】【CI/CD】docker启动的Jenkins容器 - 系统管理 - 全局工具配置 - 自动安装JDK、Maven、Git、Docker
本篇适用于jenkins是启动的docker容器,自动安装JDK Maven Git Docker等全局工具 ========================================= ...
- dotnet CLI工具是如何运行你的代码的
原文连接:https://mattwarren.org/2016/07/04/How-the-dotnet-CLI-tooling-runs-your-code/作者 Matt Warren.授权翻译 ...
- yii学习笔记(3),自定义全局工具函数
在平时开发是经常需要打印数据来调试 常见的打印方式有print_r和var_dump,但是这样打印出来格式很乱不好浏览 在打印函数前后加上<pre></pre>就可以将内容原样 ...
- Android 写一个Activity之间来回跳转的全局工具类(主要是想实现代码的复用)
废话不多说了,直接上代码,相信大家都能看得懂的. 一.主要工具类 package com.yw.chat.utils; import android.app.Activity; import andr ...
- DotNet.Utilities工具类
来源:http://git.oschina.net/kuiyu/dotnetcodes/tree/master/DotNet.Utilities
随机推荐
- God made relatives.Thank God we can choose our friends.
God made relatives.Thank God we can choose our friends. 神决定了谁是你的亲戚, 幸运的是在选择朋友方面他给了你留了余地
- VC中包含的头文件名不区分大小写
VC中包含的头文件名,不区分大小写如 #include "my.h" = #include "MY.H".
- ionic 2 起航(一)
最近的工作项目开始接触Ionic2.学习了一段时间,现在跟大家分享一下. 什么是Ionic 2? 百度一下,ionic是一个用来开发混合手机应用的,开源的,免费的代码库.可以优化html.cs ...
- 利用任务计划自动删除指定日期的SQLServer备份文件
利用任务计划自动删除指定日期的SQLServer备份文件 命令FORFILES [/P pathname] [/M searchmask] [/S] [/C command] [/D ...
- MySQL表的碎片整理和空间回收小结
MySQL表碎片化(Table Fragmentation)的原因 关于MySQL中表碎片化(Table Fragmentation)产生的原因,简单总结一下,MySQL Engine不同,碎片化的原 ...
- 本号讯 | 微软和百度携手推进全球自动驾驶技术; 微软发布新一代可垂直可水平滚动的Arc鼠标
7 月 13 日,微软宣布了与宝马的最新合作进展,继语音助手 Cortana .云服务 Azure.Office 365 和微软 Exchange 安装在部分宝马车型后——Skype for Busi ...
- Linux下如何修改用户默认目录
Linux下默认的用户目录一般为/home/xxx(root用户除外),有些时候我们可能需要修改这个目录,下面我就给大家分享2中修改的方法 工具/原料 Linux操作系统 方法/步骤 1 1.切换 ...
- ssh连接github连不上
连接github报端口22连接不上: 输入命令展示出ssh_config内容后: vim /etc/ssh/ssh_config 或者使用open /etc/ssh/ssh_config命令在文本编辑 ...
- java面试题(杨晓峰)---第三讲谈谈final、finally、finalize有什么不同?
java语言有很多看起来相似,但用途却完全不相同的语言要素,这些内容往往容易成为面试官考察你知识掌握程度的切入点. 今天我要问你一个基础的java经典题目,谈谈final.finally.finali ...
- self & this 上下文
对象:指向对象的首地址: 函数:代表了函数运行的主要上下文: 内部:在类的内部使用. self Within the body of a class method, self refers to th ...