博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Jenkins~powershell+cmd发布nuget包包
阅读量:7238 次
发布时间:2019-06-29

本文共 2184 字,大约阅读时间需要 7 分钟。

nuget包也要自动化部署了,想想确实挺好,在实施过程中我们要解决的问题有版本自动控制,nuget自动打包,nuget自动上传到服务端等。

一 参数化构建

二 环境变量的k/v参数,存储类库的初始版本,当根目录version.txt生成后,这个k/v就不需要了

 

三 这个构建跳转到哪台节点服务器

四 使用ps插件,完成version.txt的建立和更新

$initVersion=[Environment]::GetEnvironmentVariable("${env:projectName}")#版本文件目录$VersionFileDirectory="${env:WORKSPACE}/NugetServices/${env:projectName}"#版本文件名字$VersionFileName="version.txt"#版本文件路径$VersionFilePath="$VersionFileDirectory\$VersionFileName"#初始版本变量值 1.0.0.0$InitVersionValue="100";#版本长度1.0.0.0 =4$VersionLength=3Function UpdateVersion($vvalue,$vlength,$vfilepath){  $content=$(Get-Content -Path $vfilepath)  if([string]::IsNullOrEmpty($content))  {     Write-Host "version file don't exist ,creating version file......"     SetVersion $vvalue $vlength $vfilepath   }  else     {    $versionvalue=$([string]$content)    Write-Host "old version: $versionvalue"    $versionvalues=$([int]([string]$versionvalue).Replace(".",""))    $versionvalues=$(($versionvalues+1).ToString())    SetVersion $versionvalues $vlength $vfilepath   }}#设置版本值,版本名,版本值,版本长度,版本文件路径Function SetVersion($vvalue,$vlength,$vfilepath){   if(-Not (Test-Path -Path $vfilepath))   {    $null=New-Item -Path $vfilepath -ItemType File -Force   }   $value=GetVersion $vvalue $vlength   Set-Content -Path $vfilepath -Value "$value"}Function GetVersion($value,$versionlength){  $value=[string]$value  $versionlength=[int]$versionlength    $versionvalue="";  $num=$value.Length-$versionlength+1  for($i=0;$i -lt $versionlength;$i++)  {     if($i -eq 0)     {        $versionvalue= $value.Substring(0,$num)+"."     }     else      {       $index=$i+$num-1       $versionvalue=$versionvalue+$value[$index]+"."     }  }  $result=$versionvalue.Trim(".");  Write-Host "new version: $result"  return $result;}if(-Not(Test-Path -Path $VersionFilePath)){  SetVersion  $initVersion $VersionLength $VersionFilePath}else {  UpdateVersion  $InitVersionValue $VersionLength $VersionFilePath}
View Code

五 使用cmd,完成.net core项目的发布和打包,注意如果是frameworks项目,需要使用nuget.exec 完成这个功能。

NGUET方法:
nuget pack NugetServices/Pilipa.Utility -version 2.1.3
path "C:\Program Files\dotnet"cd "NugetServices/%projectName%"set /p version=

好了,以上就是我在nuget打包实现自动化部署的过程!

感谢阅读!

 

 
 

转载地址:http://krrfm.baihongyu.com/

你可能感兴趣的文章
Python简单基础小程序
查看>>
Python 购物车练习 2.0
查看>>
Hdoj 4089
查看>>
mikadonic-03-NIS+NFS+Autofs
查看>>
CSS单位解释.
查看>>
JAVA进阶18
查看>>
转 如何在secureCRT上设置常用的快捷输出按钮栏听语音
查看>>
转 Docker Swarm vs Kubernetes
查看>>
47-使用列表进行模拟栈
查看>>
Myisam和innodb 和memory的区别
查看>>
.Net 特性 attribute 学习 ----自定义特性
查看>>
vue如何加入百度联盟广告
查看>>
react中实现搜索结果中关键词高亮显示
查看>>
JQuery的过滤选择器
查看>>
C# Http POST get
查看>>
sql server 常用脚本
查看>>
88. Merge Sorted Array
查看>>
node(一)安装nodejs最新版到debian,ubuntu,mint系统
查看>>
java 多线程学习笔记
查看>>
Win10下python3和python2同时安装并解决pip共存问题
查看>>