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打包实现自动化部署的过程!

    感谢阅读!

     
     
  • 相关阅读:
    JavaScript如何获取一个元素的样式信息
    Linux服务器命令行操作(小白专用)
    Linux云服务器搭建node环境
    C++ new和delete运算符简介
    C++中free()与delete的区别
    VS2017+Qt开发时打开命令调试窗口
    opencv4.2版本遇到CV_MINMAX未声明标识符
    CUDA 数据传输
    uchar 存为8位/16位图像(QImage)
    Qt Creator删除toolbar中多余的“分隔符”
  • 原文地址:https://www.cnblogs.com/lori/p/8185128.html
Copyright © 2011-2022 走看看