Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins/Git: Build latest from branches + manual build from any commit

Tags:

git

jenkins

I am trying to set up Jenkins with a Git project so that:

  1. It will build from branches matching a pattern (origin/master, origin/feature/*, origin/hotfix/*, etc.) whenever changes are pushed to the central repository

  2. Developers and testers can trigger a build for any revision they want, specified as a build parameter that is a tag name, branch name or commit hash. The job has other parameters and we will occasionally want to create builds with something other than the default values.

I have got 1. working correctly by setting up a post-receive script on the Git server and adding multiple branch specifiers in Jenkins.

In order to also do 2., I added an extra build parameter GitRef and then added an extra branch specifier with $GitRef. Manually starting a build would then just keep building from the same commit/branch every time, whatever the parameter was set to. If I removed all the other branch specifiers, the manual builds would work as expected. But then the hook-triggered builds would only build from origin/master (the default value of $GitRef).

Is what I am trying to achieve even possible without creating a two jobs for every project? If so, what do I need to do to get it working?

like image 535
derkyjadex Avatar asked Sep 30 '13 17:09

derkyjadex


People also ask

How to use Jenkins auto-build when git commit?

In this tutorial, How to use Jenkins auto-build when git commit. You use a webhook to capture when a new git commit was made and Jenkins will start to build jobs. Ref to Install Jenkins on AWS EC2. Install the Git and Github plugins.

Why is my Jenkins commit not showing up as a branch?

(Branches parameters can contain several branches delimited by commas). The Trigger Jenkins button doesn’t send branch parameters. So if the Trigger Jenkins button launches the job but your actual commit doesn’t then first place to check is the Branches to Build parameter in your job.

What is branches to build in Jenkins?

The Branches to Build parameter is used to associate Jenkins jobs with particular branches. It can be used in pair with the Git Plugin for Jenkins. Each job configuration has a Branches to build parameter used to filter out commits so that certain jobs are only triggered for certain branches.

What is the difference between GIT checkout and Jenkins checkout?

Git performs checkout based on commit id so it ensures that correct change are built every time. You can also filter the branches to build on the Jenkins side. The Branches to Build parameter is used to associate Jenkins jobs with particular branches.


1 Answers

If you install the Git Parameters Plugin you can allow users to start a parameterized build using a specific commit ID, branch or tag.

You can then set the default value for your parameters as ** and by default, Jenkins will build the latest commit on branches.

like image 172
Wilfred Hughes Avatar answered Sep 28 '22 03:09

Wilfred Hughes