Jenkins因为windows窗体而构建块

时间:2017-06-30 04:52:30

标签: c# asp.net jenkins continuous-integration

我们有一个.net应用程序,它检查构建是否处于发布模式,并打开一个简单的窗体表格,将版本作为预构建事件输入。如果用户没有提供输入,我将此表单设置为在10秒内自动关闭。但不幸的是,在Jenkins中,构建在没有前进的情况下陷入了这一步。所以我的猜测是因为Jenkins在命令行上运行它等待用户输入继续。但即使我自动添加关闭表单,它也不会继续。有没有办法在没有UI阻止詹金斯的情况下建立这项工作?

2 个答案:

答案 0 :(得分:0)

您没有以最佳方式使用Jenkins。以下是一些可以帮助您的提示:

  • 摆脱Windows窗体以增加版本
  • 在Visual Studio解决方案中添加一个CommonAssemblyInfo.cs,其初始版本号为
  • 强制Jenkins自动增加版本[如下所述]
  • 使用git发布者或使用带有提交标志的svn.exe
  • 通过jenkins提交文件

使用powershell阅读版本号:

param([string]$assemblyInfoPath, [string]$workSpace)

$contents = [System.IO.File]::ReadAllText($assemblyInfoPath)

$versionString = [RegEx]::Match($contents,"(AssemblyFileVersion\("")(?:\d+\.\d+\.\d+\.\d+)(""\))")
Write-Host ("AssemblyFileVersion: " +$versionString)

$version = gc $assemblyInfoPath | select-string -pattern "AssemblyVersion"

$version -match '^\[assembly: AssemblyVersion\(\"(?<major>[0-9]+)\.(?<minor>[0-9]+)\.(?<revision>[0-9]+)\.(?<build>[0-9]+)\"\)\]'

$BuildVersionNumber = $matches["major"]+"."+$matches["minor"]+"."+$matches["revision"]+"."+$matches["build"]
Write-Host ("WorkSpace: " + $env:WORKSPACE.ToString()+"\version.txt")
#[Environment]::SetEnvironmentVariable("BUILD_NUMBER", $BuildVersionNumber, "Machine")

$path = $env:WORKSPACE.ToString() + "\version.txt"
$BuildVersionNumber | out-file -encoding ASCII -filepath $path

使用powershell增加版本:

#
# This script will increment the build number in an AssemblyInfo.cs file
#
param([string]$assemblyInfoPath, [string]$workSpace)

$contents = [System.IO.File]::ReadAllText($assemblyInfoPath)

$versionString = [RegEx]::Match($contents,"(AssemblyFileVersion\("")(?:\d+\.\d+\.\d+\.\d+)(""\))")
Write-Host ("AssemblyFileVersion: " +$versionString)

#Parse out the current build number from the AssemblyFileVersion
$currentBuild = [RegEx]::Match($versionString,"(\.)(\d+)(""\))").Groups[2]
Write-Host ("Current Build: " + $currentBuild.Value)

#Increment the build number
$newBuild= [int]$currentBuild.Value +  1
Write-Host ("New Build: " + $newBuild)

#update AssemblyFileVersion and AssemblyVersion, then write to file
Write-Host ("Setting version in assembly info file ")
$contents = [RegEx]::Replace($contents, "(AssemblyVersion\(""\d+\.\d+\.\d+\.)(?:\d+)(""\))", ("`${1}" + $newBuild.ToString() + "`${2}"))
$contents = [RegEx]::Replace($contents, "(AssemblyFileVersion\(""\d+\.\d+\.\d+\.)(?:\d+)(""\))", ("`${1}" + $newBuild.ToString() + "`${2}"))
[System.IO.File]::WriteAllText($assemblyInfoPath, $contents)

$version = gc $assemblyInfoPath | select-string -pattern "AssemblyVersion"

$version -match '^\[assembly: AssemblyVersion\(\"(?<major>[0-9]+)\.(?<minor>[0-9]+)\.(?<revision>[0-9]+)\.(?<build>[0-9]+)\"\)\]'

$BuildVersionNumber = $matches["major"]+"."+$matches["minor"]+"."+$matches["revision"]+"."+$matches["build"]
Write-Host ("WorkSpace: " + $env:WORKSPACE.ToString()+"\version.txt")
#[Environment]::SetEnvironmentVariable("BUILD_NUMBER", $BuildVersionNumber, "Machine")

$path = $env:WORKSPACE.ToString() + "\version.txt"
$BuildVersionNumber | out-file -encoding ASCII -filepath $path

Jenkins的用法: Increment Version in Jenkins

CommonAssembly中的版本格式:1.0.0.0

递增后:1.0.0.1

答案 1 :(得分:0)

正如Tom在评论中提到的那样,您应该看起来像添加一个选项来启动您的表单应用程序,并带有一个参数,该参数指示不应显示主表单并且应该发生一些魔术。例如,检查是否有“ / s”,如果存在,则让应用程序静默运行:

MyWinformsApplication.exe /s

而且,正如Tom所提到的,控制台应用程序仍然可以打开一个窗口,这对于在Jenkins中具有非常有用的功能,因为您可以随后将有洞察力的消息写入控制台,并将由Jenkins记录。您随时可以在以后使用它们来检查是否出了问题。

作为附加说明-如果将Console.WriteLine()添加到WinForms应用程序中,Jenkins将选择该字符串并将其添加到控制台日志中。