criticablog

ソフトウェアエンジニアがニッチな情報を書きます。

Best practice to run PowerShell scripts from Jenkins

Step-by-step

  1. Choose “Execute Windows batch command”.

  2. Paste this to print out command-lines itself to the console:

@echo off
type %0
echo.
  1. Surround your PowerShell script like this:
powershell -noprofile -command "$ErrorActionPreference = 'Stop'; Set-PsDebug -Strict; .\Do-YourJob.ps1"
  1. If your script contains external commands (like .exes or .cmds), test each exit code of them by $LASTEXITCODE:
bcp.exe blah blah
if ($LASTEXITCODE -ne 0) throw "bcp exit with $LASTEXITCODE"

Explanations

$ErrorActionPreference = 'Stop' makes powershell.exe exit with non-zero when an exception is thrown in the script (maybe).

Set-PsDebug -Strict causes an exception when a variable is used before its assignment, otherwise an uninitialized variable results $null.

Usually powershell.exe returns zero exit code (means success in Jenkins) even if the last command exit with non-zero (means failure).

The PowerShell plugin allows you to write PowerShell codes directly but I thought it would be hard to catch some kind of errors. Probably due to its invocation i.e.:

powershell.exe "& 'C:\Windows\TEMP\hudson########.ps1'" 

Nexus 7 のブラウザと webview は 別物

Chrome がプリインストールされてても、アプリ内に組み込んで使える WebView はただの WebKit ですよって話。

Nexus 7 にプリインストールされてる唯一のブラウザ Chrome で 確認くん*1 を見た様子

ブラウザーとOS Mozilla/5.0 (Linux; Android 4.3; Nexus 7 Build/JWR66Y) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Safari/537.36
サポート言語 en-US,en;q=0.8,ja;q=0.6
エンコードの仕様 gzip,deflate,sdch
MIMEの仕様 text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8

はてブ アプリ*2 の内部ブラウザで 診断くん*3 を見た様子

HTTP_ACCEPT_ENCODING gzip,deflate
HTTP_ACCEPT text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_CHARSET utf-8, iso-8859-1, utf-16, *;q=0.7
HTTP_USER_AGENT Mozilla/5.0 (Linux; U; Android 4.3; en-us; Nexus 7 Build/JWR66Y) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30
HTTP_ACCEPT_LANGUAGE en-US

感想

例えば デバイス フィンガープリンティング技術でも別デバイスとして判定されることでしょう。
Chrome 搭載端末が増えても、Android 標準ブラウザみたいなものへの配慮はいつまでも必要かも。

ちなみに端末の言語設定を英語にしてあります。