zoukankan      html  css  js  c++  java
  • Jenkins~powershell+cmd发布nuget包包

    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=3
    
    Function 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 Filesdotnet"
    cd "NugetServices/%projectName%"
    set /p version=<version.txt
    dotnet restore --configfile ../../NuGet.Config 
    dotnet build
    dotnet pack -o nugets /p:version=%version%
    dotnet nuget push nugets/%projectName%.%version%.nupkg -k abc123 -s https://nugetserver.i-counting.cn/

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

    感谢阅读!

     
     
  • 相关阅读:
    复制延迟排查
    [学习笔记]贪心
    主从复制延时判断以及脚本
    [学习笔记]尺取法
    RESET MASTER 和RESET SLAVE 命令的使用方法 注意事项
    女神(goddess)——组合数学
    主从同步设置的重要参数log_slave_updates
    埃及分数&&The Rotation Game&&骑士精神——IDA*
    多源复制开关复制命令和监控
    万圣节后的早晨&&九数码游戏——双向广搜
  • 原文地址:https://www.cnblogs.com/lori/p/8185128.html
Copyright © 2011-2022 走看看