secretbase.log

.NET/C#/Pythonなど

Windows 7 で wget および unzip を導入 (Jenkinsのビルド成果物を取得する)

例えば Jenkins さんでビルドした成果物(archive.zip)は、Webサーバ上で公開されています。
Windows上で取得、展開したい場合、どうすればいいのでしょうか。
そこで、Windows上で使える GNU 系のツール(ここでは wget と unzip) を導入してみました。

wget

  • ダウンロード

http://gnuwin32.sourceforge.net/packages/wget.htm

  • インストールする

wget-1.11.4-1-setup.exe

C:\Program Files\GnuWin32\bin

C:\Users\tkondou>wget
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\Program Files\GnuWin32/etc/wgetrc
wgetrc_file_name = C:\cygwin\home\tkondou/.wgetrc
wget: URLがありません
使い方: wget [オプション]... [URL]...

詳しいオプションは `wget --help' を実行してください。

unzip

  • ダウンロード

http://gnuwin32.sourceforge.net/packages/unzip.htm

  • インストールする

unzip-5.51-1.exe

  • 環境変数PATHに追加する ※既にしているのでここはパスしてください。

C:\Program Files\GnuWin32\bin

  • unzip の動作確認
C:\Users\tkondou>unzip
UnZip 5.51 of 22 May 2004, by Info-ZIP.  Maintained by C. Spieler.  Send
bug reports using http://www.info-zip.org/zip-bug.html; see README for details.

Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
  Default action is to extract files in list, except those in xlist, to exdir;
  file[.zip] may be a wildcard.  -Z => ZipInfo mode ("unzip -Z" for usage).

  -p  extract files to pipe, no messages     -l  list files (short format)
  -f  freshen existing files, create none    -t  test compressed archive data
  -u  update files, create if necessary      -z  display archive comment
  -x  exclude files that follow (in xlist)   -d  extract files into exdir

modifiers:                                   -q  quiet mode (-qq => quieter)
  -n  never overwrite existing files         -a  auto-convert any text files
  -o  overwrite files WITHOUT prompting      -aa treat ALL files as text
  -j  junk paths (do not make directories)   -v  be verbose/print version info
  -C  match filenames case-insensitively     -L  make (some) names lowercase
  -$  label removables (-$$ => fixed disks)  -V  retain VMS version numbers
  -X  restore ACLs (-XX => use privileges)   -s  spaces in filenames => '_'
                                             -M  pipe through "more" pager
Examples (see unzip.txt for more info):
  unzip data1 -x joe   => extract all files except joe from zipfile data1.zip
  unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer

Jenkinsさんの成果物から取得および展開

以下のようなバッチファイルを用意しました。

@echo off
REM -------------------------------------------------------------------
REM brief : jenkins archive get
REM Usage 
REM  > deploy.bat http://host/job/build_job_name/lastSuccessfulBuild/artifact/
REM -------------------------------------------------------------------
REM wget  : http://gnuwin32.sourceforge.net/packages/wget.htm
REM unzip : http://gnuwin32.sourceforge.net/packages/unzip.htm
REM -------------------------------------------------------------------
setlocal

set name=archive
set destination=.

wget %1
unzip %name%.zip

xcopy /S /E /F /G /H /R /K /Y %name%\*.* %destination%

del /q %name%.zip
rmdir /s /q %name%

引数に、Jenkinsの成果物のURLを渡してください。

> deploy.bat http://host/job/build_job_name/lastSuccessfulBuild/artifact/

Web経由で archive.zip を取得して、中身をカレントディレクトリに展開します。

xcopy を使ったりなんだか複雑です><
もっとスマートな方法がありそうな気はしています。

追記: xcopyじゃなくて move archive\*.* だとなぜかエラーがでます

Windows コマンドプロンプト ポケットリファレンス

Windows コマンドプロンプト ポケットリファレンス