0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AWS EC2にJenkinsをインストールしてCI/CD環境を構築する

Posted at

AWSのEC2インスタンスにJenkinsを導入し、継続的インテグレーション/デリバリー(CI/CD)環境を構築する手順を分かりやすくまとめました。

前提条件

  • AWSアカウントがあること
  • SSH接続用のキーペアが作成済みであること

手順

① EC2インスタンスの作成

  • インスタンスタイプ:t2.micro(無料利用枠)でも構築可能ですが、安定した運用にはt3.medium以上を推奨します。
  • OS:Amazon Linux 2
  • セキュリティグループ:以下のポートを許可
    • TCP 8080(Jenkins)
    • TCP 22(SSH)

② EC2インスタンスにSSH接続

ssh -i your-key.pem ec2-user@<EC2のパブリックIP>

③ Jenkinsおよび関連ソフトウェアのインストール

Javaをインストールします。

sudo yum update -y
sudo amazon-linux-extras install java-openjdk17 -y

Jenkinsリポジトリを追加してインストールします。

sudo wget -O /etc/yum.repos.d/jenkins.repo \
    https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key

sudo yum install jenkins git -y

④ Jenkinsの起動

Jenkinsを起動し、自動起動を有効化します。

sudo systemctl start jenkins
sudo systemctl enable jenkins

起動を確認します。

sudo systemctl status jenkins

⑤ Jenkinsのポート変更(必要に応じて)

他のアプリケーションとポートが競合する場合は、ポートを変更できます。

sudo vi /etc/sysconfig/jenkins

変更例(8089に変更する場合):

JENKINS_PORT="8089"

設定後にJenkinsを再起動します。

sudo systemctl restart jenkins

⑥ ブラウザからJenkinsにアクセス

ブラウザで以下にアクセスします。

http://<EC2のパブリックIP>:8080

初期パスワードを以下のコマンドで確認します。

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

表示されたパスワードを入力して、初期設定を完了してください。

Jenkins管理画面の初期設定

  • 「Install suggested plugins」(推奨プラグインをインストール)を選択します。
    image.png

  • 初期管理者ユーザーを作成し、ログインします。

以上でAWS EC2上でのJenkins環境構築が完了しました。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?