(TFS Team Foundation Server Git Build Jenkins)
もはや今更感しかないですが、GitレポジトリのビルドをJenkinsのJOBで行います。
今回は、TFSのGitレポジトリを対象をしてビルドを行います。
GitHubではなく、TFSのGit
いま時点(2016/05/29)では、Jnekinsは2.6がリリースされていますが、今回はあえて1.6で解説します。
Jnekins2.6では、必要なプラグインが初期状態でインストールされていますが、1.6ではユーザが追加する必要があります。
環境
実行環境 | Windows |
---|---|
Jenkins | 1.651.2 |
TFS Team Foundation Server | 2013 Update2 |
Jenkinsは、1.6をインストールした素の状態です。
手順
- JenkinsにGitPluginをインストール
- 認証情報の設定
- プロジェクトのソース管理の設定
- ビルドの設定
JenkinsにGitPluginをインストール
Jenkinsの管理 -> プラグインの管理 -> 利用可能 -> Git Plugin
Git Pluginにチェックを入れてインストールします。
この時、必要な他のプラグインもインストールされてます。
これで、各プロジェクト設定のソースコード管理からGitが選択可能となります。
また、Jnekins2.6では、Git Pluginが予めインストールされているのでこの手順は不要です。
認証情報の設定
TFSのGitレポジトリへの認証情報を"Jnenkins"に設定します。
TFVC(TFSの集中管理のレポジトリ)の場合には、"各プロジェクト"に認証情報を設定しますが、Gitの場合には違うので注意(?)が必要です。
※ココが一番ハマりました。ちゃんと説明読んでなかっただけですけどね
TFSの認証はWindows認証を使用します。予め、ドメインにJnenkins用のユーザを登録しチームプロジェクトへのアクセス権限は付与した状態です。
今回は、簡単にグローバルドメインに認証情報を追加しますが、ココは組織のポリシーに合わせてください。
Jenkins -> 認証情報 -> System -> グローバルドメイン
なにもないので認証情報を追加してきます。
種類 | ユーザ名とパスワード |
---|---|
スコープ | グローバル |
ユーザ名 | ドメイン名\ユーザ |
パスワード | ユザーのパスワード |
プロジェクトのソース管理の設定
ソース管理の設定にレポジトリURLとか一つ前で設定した認証情報を設定します。
あと、ビルドブランチとかね
Jnenkins -> #プロジェクト# -> 設定
Repository URL | http://{TFSサーバ名}:8080/tfs/{コレクション名}/_git/{チームプロジェクト名} |
---|---|
Credentials | 前の手順で作成した認証情報を選択 |
Branches to build | master |
これで、TFSのGitからソース取得が行えます。
実行のログから、初回なのでCloneしていることがわかります。
ユーザーanonymousが実行
ビルドします。 ワークスペース: C:\Program Files (x86)\Jenkins\jobs\TFSGitBuildSample\workspace
Cloning the remote Git repository
Cloning repository http://{TFSサーバ}:8080/tfs/{コレクション}/_git/{TFSチームプロジェクト}
> git.exe init C:\Program Files (x86)\Jenkins\jobs\TFSGitBuildSample\workspace # timeout=10
Fetching upstream changes from http://{TFSサーバ}:8080/tfs/{コレクション}/_git/{TFSチームプロジェクト}
> git.exe --version # timeout=10
using .gitcredentials to set credentials
> git.exe config --local credential.username inside\dev_admin # timeout=10
> git.exe config --local credential.helper store --file=\"C:\Windows\TEMP\git303406921920127966.credentials\" # timeout=10
> git.exe -c core.askpass=true fetch --tags --progress http://{TFSサーバ}:8080/tfs/{コレクション}/_git/{TFSチームプロジェクト} +refs/heads/*:refs/remotes/origin/*
> git.exe config --local --remove-section credential # timeout=10
> git.exe config remote.origin.url http://{TFSサーバ}:8080/tfs/{コレクション}/_git/{TFSチームプロジェクト} # timeout=10
> git.exe config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
> git.exe config remote.origin.url http://{TFSサーバ}:8080/tfs/{コレクション}/_git/{TFSチームプロジェクト} # timeout=10
Fetching upstream changes from http://{TFSサーバ}:8080/tfs/{コレクション}/_git/{TFSチームプロジェクト}
using .gitcredentials to set credentials
> git.exe config --local credential.username inside\dev_admin # timeout=10
> git.exe config --local credential.helper store --file=\"C:\Windows\TEMP\git943761686886846662.credentials\" # timeout=10
> git.exe -c core.askpass=true fetch --tags --progress http://{TFSサーバ}:8080/tfs/{コレクション}/_git/{TFSチームプロジェクト} +refs/heads/*:refs/remotes/origin/*
> git.exe config --local --remove-section credential # timeout=10
> git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
> git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision 4d40f361aca9cdcbf5793767389452bd209373ad (refs/remotes/origin/master)
> git.exe config core.sparsecheckout # timeout=10
> git.exe checkout -f 4d40f361aca9cdcbf5793767389452bd209373ad
First time build. Skipping changelog.
Finished: SUCCESS