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?

More than 1 year has passed since last update.

【Jenkins】GitHub連携②

Last updated at Posted at 2023-10-12

はじめに

今回やること
 ・リモートブランチにコミットされたことを検知したら、ローカルブランチにPullするShellを作成

GitHub連携

  • GitHubのアクセストークンをJenkinsに登録
    GitHub側でトークンを生成します。
    image.png
    生成したトークンをJenkinsのcredentialsに登録する。(ユーザーIDとパスワード)
    ※パスワードにアクセストークンを入れます。
    image.png

  • JenkinsのAPIトークンを生成
    開発者⇒ユーザーを選択⇒設定からAPIトークンを生成します。トークンの名前は何でも良いです。
    image.png

  • Webhooksの設定
    image.png

Payload URLは↓以下のように設定します。
http://[Jenkinsのユーザー名]:[JenkinsのAPIトークン]@[サーバのIPアドレス:ポート]/job/[Jenkinsのジョブの名前]/buildWithParameters?token=[JenkinsのAPIトークンの名前]
「Add webhook」で登録します。

  • ジョブの作成
    新規ジョブの作成⇒フリースタイル・プロジェクトのビルドでジョブの内容を決めていきます。
    GitHub projectにチェックを入れます。
    Project urlにはリモートリポジトリのURLを入力します。(例:https://github.com/××/××.git)
    ビルドのパラメータ化にチェックを入れて、名前にはpayloadと入力します。
    image.png

ソースコードの管理ではGitにチェックを入れて、リポジトリURLを入れます。
※Project urlと同じで良いです。
認証情報では、GitHubのアクセストークンを、セレクトボックスから選択します。
image.png
ブランチの名前は適宜変えてください。
image.png

認証トークンにはJenkinsのAPIトークンの名前を入れてください。
image.png

ビルド環境のリモートホストでシェルを実行にチェックを入れ、SSHサイトでは登録しているIPアドレスを選択します。
ビルド前スクリプトには、ローカルリポジトリの場所に移動して「git pull」をするshellを書きます。

image.png

最後に保存を押します。

【Jenkins】GitHub連携①:https://qiita.com/mojapico/items/9c114f0890adaf3a0862

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?