[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
随机推荐
- HDU 2899Strange fuction(模拟退火)
题意 题目链接 求 $F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)$的最小值 Sol 强上模拟退火,注意eps要开大! /* */ ...
- All boundaries are conventions, waiting to be transcended.
All boundaries are conventions, waiting to be transcended.所有界限都是陈规,等着被打破.
- CSS3学习-用CSS制作立体导航栏
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【js类库AngularJs】解决angular+springmvc的post提交问题
[js类库AngularJs]解决angular+springmvc的post提交问题 AngularJS诞生于2009年,由Misko Hevery 等人创建,后为Google所收购.是一款优秀的前 ...
- github入门之更改提交操作--6
1.回溯历史版本 1.1.回溯到创建feature-A分支前 1.1.1.要让仓库的HEAD.暂存区.当前工作树回溯到指定状态,需要用到提供目标时间点的哈希值 1.1.2.回溯至未创建feature- ...
- POJ 2288 Islands and Bridges (状压DP,变形)
题意: 给一个无向图,n个点m条边,每个点有点权,要求找到一条哈密顿路径,使得该路径的f(path)值最大.输出f值,若有多条最大f值的路径,输出路径数量. f值由如下3点累加而来: (1)所有点权之 ...
- FlowVisor相关
1. FlowVisor工作原理(转) 作为一个网络虚拟化平台,FlowVisor部署在标准OpenFlow控制器和OpenFlow交换机之间,成为二者的透明代理.FlowVisor能够与多个控制器连 ...
- HDU - 5491 The Next 2015 ACM/ICPC Asia Regional Hefei Online
从D+1开始,对于一个数x,区间[x,x+lowbit(x))内的数字的二进制位上1的数量整体来说是单调不减的,因此可快速得出1在这个区间的取值范围. 每次判断一下有没有和[s1,s2]有没有交集,一 ...
- 三、npm start报错:./node_modules/history/esm/history.js解决办法
package.json中的roadhog换为:'^2.5.0-beta.4',删除node_modules文件夹,在执行npm install,npm start.
- 2018.3.11 Java DEBUG 调试的方法
F5:Step Into:跳进当前执行的方法中 F6:Step Over:跳过该行继续执行 F7:Step Return:从方法中跳出继续执行 F8:Resume:全部运行通过,从调试状态恢复 Ctr ...