如何阻止Jenkins在第80列截断/换行

时间:2016-06-21 17:33:51

标签: powershell jenkins

我有一个在Jenkins构建中执行的Powershell构建步骤,并且控制台将输出包装在第80列(似乎是默认值)。有没有办法阻止这个列包装并让Jenkins为我们期望的输出使用更合适的列宽?

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。我通过这个link发现你可以增加控制台的宽度和高度。我被限制在最大128 W和62 H但我会得到错误。

所以我最终得到了这个:

$pshost = get-host

$pswindow = $pshost.ui.rawui

$newsize = $pswindow.buffersize

$newsize.height = 3000

$newsize.width = 128

$pswindow.buffersize = $newsize

$newsize = $pswindow.windowsize

$newsize.height = 62

$newsize.width = 128

$pswindow.windowsize = $newsize

由于此宽度不够,当我输出一个对象数组时,我将它传递给format-table cmdlet并使用-Wrap开关。

E.g。

Get-EventLog -LogName Application -Newest 10 | Format-Table -Wrap

产生以下输出:

enter image description here

答案 1 :(得分:1)

尽管Avner的答案是正确的,但我发现,每次詹金斯管道遇到新的powershell步骤时,都必须重新定义窗口和缓冲区大小。

避免这种情况的一种方法是为 powershell.exe 设置默认窗口和缓冲区大小。 mkelement0 in his answer说明了一种实现方法。

  

以编程方式设置powershell.exe窗口大小默认值:

     

以下PSv5 +代码段将powershell.exe启动的控制台窗口的默认窗口大小设置为100列乘50行。

     

请注意,屏幕的 buffer 值是根据直接存储在HKCU:\Console中的总体默认设置继承的,会增加复杂性。

# Determine the target registry key path.
$keyPath = 'HKCU:\Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe'

# Get the existing key or create it on demand.
$key = Get-Item $keyPath -ErrorAction SilentlyContinue
if (-not $key) { $key = New-Item $keyPath }

# Determine the new size values.
[uint32] $cols = 100; [uint32] $lines = 50
# Convert to a DWORD for writing to the registry.
[uint32] $dwordWinSize = ($cols + ($lines -shl 16))

# Note: Screen *buffer* values are inherited from 
#       HKCU:\Console, and if the inherited buffer width is larger
#       than the window width, the window width is apparently set to 
#       the larger size.
#       Therefore, we must also set the ScreenBufferSize value, passing through
#       its inherited height value while setting its width value to the same
#       value as the window width.
[uint32] $dwordScreenBuf = Get-ItemPropertyValue HKCU:\Console ScreenBufferSize -EA SilentlyContinue
if (-not $dwordScreenBuf) {  # No buffer size to inherit.
  # Height is 3000 lines by default. 
  # Note that if we didn't set this explicitly, the buffer height would 
  # default to the same value as the window height.
  $dwordScreenBuf = 3000 -shl 16  
}

# Set the buffer width (low word) to the same width as the window
# (so that there's no horizontal scrolling).
$dwordScreenBuf = $cols + (($dwordScreenBuf -shr 16) -shl 16)

# Write the new values to the registry.
Set-ItemProperty -Type DWord $key.PSPath WindowSize $dwordWinSize
Set-ItemProperty -Type DWord $key.PSPath ScreenBufferSize $dwordScreenBuf