postman + newman + jenkins on Windows10
webapiをpostmanとnewmanを使ってテストし、Jenkinsで自動化できるか確認した。
newmanのコマンドは、以下の通り。
F:\etc>newman run gettest.postman_collection.json -e local.postman_environment.json
newman
gettest
→ getValues-0
GET http://localhost:64587/api/values?id=0 [304 Not Modified, 295B, 106ms]
1. Status code is 200
→ getValues-1
GET http://localhost:64587/api/values?id=1 [200 OK, 358B, 7ms]
√ Status code is 200
→ postValues-title-ok
POST http://localhost:64587/api/values [200 OK, 355B, 8ms]
√ Status code is 200
→ postValues-title-non
POST http://localhost:64587/api/values [304 Not Modified, 295B, 44ms]
2. Status code is 200
┌─────────────────────────┬───────────────────┬──────────────────┐
│ │ executed │ failed │
├─────────────────────────┼───────────────────┼──────────────────┤
│ iterations │ 1 │ 0 │
├─────────────────────────┼───────────────────┼──────────────────┤
│ requests │ 4 │ 0 │
├─────────────────────────┼───────────────────┼──────────────────┤
│ test-scripts │ 4 │ 0 │
├─────────────────────────┼───────────────────┼──────────────────┤
│ prerequest-scripts │ 0 │ 0 │
├─────────────────────────┼───────────────────┼──────────────────┤
│ assertions │ 4 │ 2 │
├─────────────────────────┴───────────────────┴──────────────────┤
│ total run duration: 289ms │
├────────────────────────────────────────────────────────────────┤
│ total data received: 11B (approx) │
├────────────────────────────────────────────────────────────────┤
│ average response time: 41ms [min: 7ms, max: 106ms, s.d.: 40ms] │
└────────────────────────────────────────────────────────────────┘
# failure detail
1. AssertionError Status code is 200
expected response to have status code 200 but got 304
at assertion:0 in test-script
inside "getValues-0"
2. AssertionError Status code is 200
expected response to have status code 200 but got 304
at assertion:0 in test-script
inside "postValues-title-non"
CLIで毎回たたくよりJenkinsの方が効率がいい。
Jenkinsをインストールすると、http://localhost:8080で立ち上がる。
ここから設定手順
1. 新規ジョブ作成をクリック
2.アイテム名を入力して、「フリースタイル・プロジェクトのビルド」をクリック
3.ビルドタブ→「ビルド手順の追加」→「シェルの実行」をクリック
4.シェルスクリプトを入力する
5.実行してみる
(エラー対応)
実行エラー1
newmanのジョブを実行すると以下のようなエラーが発生する。
ビルドします。 ワークスペース: C:\Program Files (x86)\Jenkins\workspace\NewMan_Test
[NewMan_Test] $ sh -xe C:\WINDOWS\TEMP\jenkins1609177038110875101.sh
+ newman run F:etcgettest.postman_collectionok.json -e F:etclocal.postman_environment.json
C:\WINDOWS\TEMP\jenkins1609177038110875101.sh: line 2: newman: command not found
Build step 'シェルの実行' marked build as failure
Finished: FAILURE
解決策
要は、newmanのパスが通ってないのだ。
「Jenkinsの管理」→「システムの設定」→「グローバル プロパティ」
キー→PATH
値→$PATH;C:\Users\kumag\AppData\Roaming\npm
実行エラー2
[NewMan_Test] $ sh -xe C:\WINDOWS\TEMP\jenkins7001615507996501103.sh
+ newman run F:etcgettest.postman_collectionok.json -e F:etclocal.postman_environment.json
error: could not load environment
ENOENT: no such file or directory, open 'F:\etclocal.postman_environment.json'
解決策
なんか、パスがおかしい。
「\」を認識していない?
「\」を「/」に変えてみる。
やっと通った。
参考
- Integrating with Jenkins
- windowsマシンを再起動したときのjenkins再起動方法
- Cannot run newman on jenkins [newman :command not found] in AWS EC2 Linux Jenkin machine
コメント
コメントを投稿