2017-06-30 83 views
0

我們有一個.net應用程序,用於檢查構建是否處於發佈模式,並打開一個簡單的窗體來將版本作爲預構建事件輸入。如果用戶沒有提供輸入,我會在10秒內自動關閉表單。但不幸的是,在詹金斯,構建卡住了這一步而沒有前進。所以我的猜測是,因爲Jenkins在命令行上運行,所以等待用戶繼續輸入。但即使我添加自動關閉表單,它不會繼續。有沒有一種方法可以在沒有UI阻止Jenkins的情況下構建這項工作?Jenkins構建基於Windows窗體的塊

+0

爲什麼用戶必須輸入版本號?構建尚未發生,所以這不是最好的做法,請參閱其他想法以獲取版本號:https://stackoverflow.com/questions/15222243/set-assemblyinfo-version-numbers-with-msi -setup-version –

+1

將命令行處理添加到應用程序以提供無人蔘與的操作模式。 (如果Jenkins要求調用者等待進程結束,它仍然可以是一個窗口應用程序,另一方面,它可能是一個控制檯應用程序,並且仍然會打開一個窗口。) –

回答

0

您沒有以最佳方式使用Jenkins。這裏有一些技巧來幫助你:

  • 擺脫你的Windows窗體的遞增版本
  • 在Visual Studio解決方案添加CommonAssemblyInfo.cs與最初的版本號
  • 隊詹金斯遞增版本自動[下文描述]
  • 用git出版商或使用svn.exe提交由詹金斯文件與提交標誌

讀版本號使用的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 

用法在詹金斯:在CommonAssembly Increment Version in Jenkins

版本格式:1.0.0.0

遞增後:1.0.0.1