开发者

Jenkins and multiple git branches?

开发者 https://www.devze.com 2023-04-02 17:22 出处:网络
I\'m working on a Jenkins job and i need it to build two branches in the same repository. How can i do this开发者_StackOverflow社区?Considering that Jenkins cannot execute one job on two versions of a

I'm working on a Jenkins job and i need it to build two branches in the same repository. How can i do this开发者_StackOverflow社区?


Considering that Jenkins cannot execute one job on two versions of a repository (which is what would be getting the content of two different branches), I would suggest making two different jobs, one for each branch (with the Jenkins Git plugin).


Are you asking if you want to build two branches in the same checked-out workspace directory?

If in the same workspace directory, all you need to do is create a script that will checkout one branch, build it, and when done, checkout the next branch and then build it.

This single script will then be the one to be called by the single Jenkins job.

For example, your build script would look something like this:

git clone url:repo.git workspace
cd workspace 
git checkout branchA
make
# now you're done building branchA
# next checkout branchB and run make
git checkout branchB
make
# now you are done building branchB

Each checkout will install the files for the branch desired. And this will build it accordingly. However, since they will be sharing the same workspace directory, this could mean that new files would be produced by the first build which will then be present when the second build runs. I assume this is the effect that you want because you wanted to build two branches in the same workspace directory.

Update: Use git clean -xdf if you want to have a fresh workspace for the next build.


This plugin will build every branch for you: https://wiki.jenkins-ci.org/display/JENKINS/Multi-Branch+Project+Plugin.

You can also use the GitLab (https://wiki.jenkins-ci.org/display/JENKINS/GitLab+Plugin) / GitHub (https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Plugin) plugins, which can trigger a build when code is commited, and will then build the branch that was comitted to.


IF you want the above AND want the advanced feature where Jenkins builds any new branch and merges that to master ONLY if the build succeeds(ie. you want two master branches and two builds), you may want to think about just forking the repository and merging changes between repositories(git is built for that kind of thing though I have not quite gotten to that point of usage yet).

So you would basically have 2 git repositories and two jenkins builds and you can configure the git plugin to build from any branch in each repository and merge into master of that repository. So, each repository is acting like a branch in this configuration.

That is our plan when we start a new release line 2.x from our 1.x release line at any rate is to fork. We will see how it works in practice.

later, Dean

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号