kb84tkhrのブログ

何を書こうか考え中です あ、あと組織とは関係ないってやつです 個人的なやつ

GitHub実践入門(15)

 やっとJenkinsに戻る
どこからだ

ああWhite ListにCollaboratorを登録するところからね
だから別アカウント作ったんだった
本のスクリーンショットよりもかなり項目が増えてて探しづらいぞ

「ビルド」でビルド手順を追加
この場合はテストを実行させるくらい?
テストはどこで実行するんだ?
Jenkinsの動いてるサーバ(今は自分のMac)だよな
単純にこれでいいの?

python3 test-hoge.py

このシェルスクリプトが0返したらOKってことだねたぶん

さてこれでひととおりやってみたわけだが
テストはどうしたらいんだ?
「ビルド実行」かな

計算に失敗されたそうです
ログを見る

ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.

ビルドする対象がないからブランチ設定を見直せってさ

調べる
${sha1}って何か気になるんだけどとにかく${sha1}と設定する、としか
書いてないところがほとんど
でもこれ、なんか環境変数を読んでるっぽいな
SHA1っていう環境変数・・・?あんまり聞いたことないな

そもそもBranch Specifierってのはなんだ
空白なら全ブランチを対象にする
masterって書けばmasterをチェックする
もしかして、SHA1ってコミットのハッシュのことか
あーわかるといえばわかる

それはそれとしてなぜ失敗しているのか
ログをもっとよく見る

 > git fetch --tags --progress https://github.com/koba925/learn-travisci +refs/pull/*:refs/remotes/origin/pr/*
 > git rev-parse origin/${sha1}^{commit} # timeout=10
 > git rev-parse ${sha1}^{commit} # timeout=10

あたりがrevision to buildを見つけてくれてないってことっぽい

 > git fetch --tags --progress https://github.com/koba925/learn-travisci +refs/pull/*:refs/remotes/origin/pr/*

はプルリクエストを探してて

 > git rev-parse origin/${sha1}^{commit} # timeout=10
 > git rev-parse ${sha1}^{commit} # timeout=10

は指定された名前(ここでは${sha1}のコミットを探している模様
${sha1}^{commit}は何かというとgit rev-parseのヘルプにそれっぽいのがあった

$ git rev-parse --help
       ...
       <rev>^{<type>}, e.g. v0.99.8^{commit}
           A suffix ^ followed by an object type name enclosed in brace pair
           means dereference the object at <rev> recursively until an object
           of type <type> is found or the object cannot be dereferenced
           anymore (in which case, barf). For example, if <rev> is a
           commit-ish, <rev>^{commit} describes the corresponding commit
           object. ...

コミット系の名前をハッシュに変換してくれるものっぽい
${sha1}^{commit}であれば${sha1}が"master"であれば
masterのハッシュが返るって感じ

まあプルリクエストがないからだな普通に考えて

プルリクエストを出す
お、ビルドが動いてる
成功

GitHub pull request #3 of commit f69544b4a33be7bbaab7195341adf2a2524a48db, no merge conflicts.
Setting status of f69544b4a33be7bbaab7195341adf2a2524a48db to PENDING with url http://localhost:8080/job/ghprb%20test/15/ and message: 'Build started for merge commit.'
ビルドします。 ワークスペース: /Users/jenkins/.jenkins/workspace/ghprb test
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/koba925/learn-travisci # timeout=10
Fetching upstream changes from https://github.com/koba925/learn-travisci
 > git --version # timeout=10
 > git fetch --tags --progress https://github.com/koba925/learn-travisci +refs/pull/*:refs/remotes/origin/pr/*
 > git rev-parse refs/remotes/origin/pr/3/merge^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/pr/3/merge^{commit} # timeout=10
Checking out Revision 99846ddae2bfebbcdd8b5cc8b5b9b09a7f9347bf (refs/remotes/origin/pr/3/merge)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 99846ddae2bfebbcdd8b5cc8b5b9b09a7f9347bf
Commit message: "Merge f69544b4a33be7bbaab7195341adf2a2524a48db into 16e7792afd0eb726c484d8edc2d660b979c1d13a"
First time build. Skipping changelog.
[ghprb test] $ /bin/sh -xe /var/folders/_8/wfczhcd90kd2ffm0n8svbxgh0000gq/T/jenkins391701831127769220.sh
+ python3 test-hoge.py
...
----------------------------------------------------------------------
Ran 3 tests in 0.000s

OK
Setting status of f69544b4a33be7bbaab7195341adf2a2524a48db to SUCCESS with url http://localhost:8080/job/ghprb%20test/15/ and message: 'Build finished. '
Finished: SUCCESS

プルリクエストがあると

 > git rev-parse origin/${sha1}^{commit} # timeout=10
 > git rev-parse ${sha1}^{commit} # timeout=10

のほうは探さないのかな

~jenkins/.jenkins/workspace/ghprb testの下も最新になって
マージもされている模様

$ git log --oneline
99846dd (HEAD, origin/pr/3/merge) Merge f69544b4a33be7bbaab7195341adf2a2524a48db into 16e7792afd0eb726c484d8edc2d660b979c1d13a
f69544b (origin/pr/3/head) Yet updated mogemoge

こんどはブラウザ上でマージしたりしてみた
当然問題なく成功

なんかHello World的なものをすっとばしてる気がして
もっと基本から調べたほうがいい気もするけど
必要になってからでいいかなあ

ということでJenkinsもこれくらいにして
GitHub実践入門はここまでということで
スタックを戻ります