LoginSignup
30
32

More than 5 years have passed since last update.

BitbucketのプライベートリポジトリをJenkinsからビルド

Last updated at Posted at 2013-11-04

OSはUbuntu 12.04.3 LTSです。
今更ながらJenkinsをインストールします。

インストール

wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins

インストールすると、Jenkinsがデーモンとして登録されます。

起動

sudo service jenkins start

デフォルトは8080ポートで開始されるので、ブラウザに表示されるのが嫌な人はリバースプロキシでなんとかします。

jenkins1.png

セキュリティ設定

デフォルト設定のままでは、誰でも閲覧可能な状態になっています。
プライベートなネットワーク上であればデフォルトで全く問題ないですが、そうでない場合は問題なので ログイン済みユーザーのみ閲覧可能な設定 にします。

グローバルセキュリティ設定の権限の管理を、 行列による権限設定 にします。

あとは権限を下記の通り設定する事で、ログイン済みユーザーからのみJenkinsのページが閲覧可能になります。

  • ユーザーを作成して、権限を付与
  • 匿名ユーザーは権限を剥奪

jenkins2.png

Jenkins がリポジトリにアクセスする準備

(Ubuntu上の)Jenkinsユーザーで公開鍵を作り、Bitbucketにデプロイキーとして作成した公開鍵を設定します。

jenkins3.png

sudoが使えない環境の際は、Jenkinsの画面からシェルを実行できるようなのでそちらから公開鍵の作成すれば大丈夫みたいです。

Bitbucket にデプロイキーを登録したので、Ubuntuに対してホストを認証させます。

$ ssh bitbucket.org
The authenticity of host 'bitbucket.org (131.103.20.168)' can't be established.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'bitbucket.org,131.103.20.168' (RSA) to the list of known hosts.
PTY allocation request failed on channel 0
authenticated via a deploy key.

You can use git or hg to connect to Bitbucket. Shell access is disabled.
Connection to bitbucket.org closed.

プロジェクトの設定

事前に管理画面からgit pluginをJenkinsにインストールしてください。

適当にプロジェクトを作り、リポジトリと認証トークンを設定します。
jenkins4.png

リモートからビルドの説明通りのアドレスにアクセスを行うとビルドが始まるようになります。

jenkins5.png

30
32
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
32