8

10 ~ 15 個の git ブランチがありますが、そのうちの 2 つ ("master" と "beta1") でのみ Jenkins ジョブをトリガーしたいと考えています。Jenkins 用のGit プラグインを使用し、「構築するブランチ」セクションで「master」と「beta1」の両方を指定しています。また、「リポジトリのローカル サブディレクトリ (オプション)」フィールドで ${GIT_BRANCH} を指定しています。

マスター ブランチにチェックインが表示されたときにのみ、マスター ブランチでのみJenkins ジョブをトリガーしたいと考えています。

beta1 ブランチにチェックインが表示された場合にのみ、beta1 ブランチでのみJenkins ジョブをトリガーしたいと考えています。

これらのブランチの両方を同じ Jenkins ジョブで制御して、ビルド番号が 2 つのブランチ間で一意になるようにします (2 つの異なるジョブにある場合、ビルド番号は同じになる可能性があります)。

現在、master ブランチからのチェックインのために beta1 ブランチでジョブをトリガーしているようです。ログから (注: 以下のログの最初の行で報告されているようにトリガーされた変更は、マスター ブランチからのものです):

Started by remote host (IP) with note: Triggered by push of revision e4391d0049ff: "blah" to (URL) by (USER)
Building in workspace /var/lib/jenkins/jobs/Orca/workspace
Checkout:workspace / /var/lib/jenkins/jobs/Orca/workspace - hudson.remoting.LocalChannel@3ae1a582
Using strategy: Default
Last Built Revision: Revision 7e2aae6c752a16516d9f6ac48944492a4e3596d4 (origin/master)
Wiping out workspace first.
Cloning the remote Git repository
Cloning repository (SSH)
git --version
git version 1.7.4.1
Fetching upstream changes from origin
Cleaning workspace
Resetting working tree
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/beta1
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/master
Seen branch in repository origin/(BLAH)
Seen 22 remote branches
Multiple candidate revisions
Scheduling another build to catch up with Orca
Commencing build of Revision eaad42c836a87672c546d61f310cc31bf03ecb97 (origin/beta1)
Checking out Revision eaad42c836a87672c546d61f310cc31bf03ecb97 (origin/beta1)
4

3 に答える 3

0

別の方法は、gitのポスト コミット フックを使用することです。これにより、ポーリングよりもビルドをすばやく開始できる場合もあります。


Jenkins に次の変更を加えます。

  1. Parameterized Build プラグインがインストールされていることを確認します。
  2. 問題のジョブをパラメータ化するように構成します。このパラメータに「BRANCH_TO_BULD」という名前を付けることを検討してください。「マスター」のデフォルト値を検討してください
  3. ソースコード管理を「なし」に設定
  4. ポーリングを無効にする
  5. ビルド ステップの最初で、次のシェル コマンドを実行します。

cd /path/to/your/workspace/SpecialJob 
git reset --hard 
git clean -f -d 
git fetch origin 
git checkout $BRANCH_TO_BUILD  



Git に次の変更を加えます。

  1. まず、元のgit リポジトリのルートにある hooks ディレクトリに移動します。
  2. post-receive.sample の名前を post-receive に変更します
  3. ファイルの内容を編集して、以下を含めます (MyJenkinsBox と MySpecialJob を変更します)。

echo  
# if you want to send some fancy text to the committer's console output.
echo Post Receive Hook  
echo  
while read oldrev newrev refname  
do  
    branch=$(git rev-parse --symbolic --abbrev-ref $refname)  
    # only build for master  
    if [ "master" == "$branch" || "beta1" == "$branch" ]; then  
        # more valuable feedback to the committer's console output  
        echo Building MySpecialJob job on Jenkins. Branch = $branch  
        echo  
        curl -s -X POST http://MyJenkinsBox:8080/job/MySpecialJob/buildWithParameters?BRANCH_TO_BUILD=$branch  
        echo  
    fi
done
于 2014-05-09T10:26:43.983 に答える