Trying to extend FreeStyleProject to override a method

26 views
Skip to first unread message

PaulD

unread,
Jan 7, 2016, 6:13:34 AM1/7/16
to jenkin...@googlegroups.com
I'm trying to write my first plugin, so apologies for the probably very
obvious questions.

I'm trying to extend FreeStyleProject so that I can override the
'getIconColor' method with some custom functionality (currently just sets it
to 'Not built' for testing but will be doing more later). My current code is
as follows:

package GitBranchFailureNotifier.GitBranchFailureNotifier;
import hudson.Extension;
import hudson.model.BallColor;
import hudson.model.FreeStyleProject;
import hudson.model.ItemGroup;
import hudson.model.TopLevelItem;
import hudson.model.TopLevelItemDescriptor;

public class GitBranchFailureNotifierFreeStyleProject extends
FreeStyleProject {



public GitBranchFailureNotifierFreeStyleProject(ItemGroup parent,
String name) {
super(parent, name);
}

@Override
public BallColor getIconColor() {
return BallColor.NOTBUILT;
}

@Extension
public static final class CustomJobDescriptor extends
TopLevelItemDescriptor
{

@Override
public String getDisplayName() {
return "Git Branch Failure Notifier";
}

@Override
public TopLevelItem newInstance(ItemGroup arg0, String arg1)
{
return new
GitBranchFailureNotifierFreeStyleProject(arg0, arg1);
}

}
}

What I was expecting to happen was for this to show up as a new build type
option alongside the existing set of builds, but clearly I'm doing something
wrong.

Also if there is a better way to override a method (ideally I'd like to do
this for all jobs on our server) please let me know.

Thanks.



--
View this message in context: http://jenkins-ci.361315.n4.nabble.com/Trying-to-extend-FreeStyleProject-to-override-a-method-tp4788542.html
Sent from the Jenkins dev mailing list archive at Nabble.com.

Vincent Latombe

unread,
Jan 7, 2016, 9:36:48 AM1/7/16
to Jenkins Dev
I don't really know the full extent of what you are trying to achieve, but I wouldn't get down the road of writing a new kind of project 'just' for this.

If it is about swapping some icons depending on an custom criteria, I'd take a look at https://github.com/jenkinsci/greenballs-plugin and build something similar (the interesting bits are in https://github.com/jenkinsci/greenballs-plugin/blob/master/src/main/java/hudson/plugins/greenballs/GreenBallFilter.java)

Vincent


--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/1452163972569-4788542.post%40n4.nabble.com.
For more options, visit https://groups.google.com/d/optout.

PaulD

unread,
Jan 7, 2016, 9:50:02 AM1/7/16
to jenkin...@googlegroups.com
I did see that plugin, but I need properties of the project itself in order
to decide which icon to show. The green balls plugin (as far as I can tell?)
just replaces the default blue ball with a green ball (plus some colourblind
support). Is there any way to work out what project the ball is being shown
for?

The reason I am doing this is that we are using the git plugin to define a
build against two different branches. This is causing us problems because on
the main summary it only displays the most recent build status. For instance
if the /master build fails, but then the /branch build passes, the front
page displays the build as passing. What we want is to display the 'worst
case' out of the two branches on the front page.



--
View this message in context: http://jenkins-ci.361315.n4.nabble.com/Trying-to-extend-FreeStyleProject-to-override-a-method-tp4788542p4788607.html

Vincent Latombe

unread,
Jan 7, 2016, 9:59:41 AM1/7/16
to Jenkins Dev
git plugin support for multiple branches is considered a hack by many people as it causes a lot of underlying problems. Maybe for your case, you could have a look at https://wiki.jenkins-ci.org/display/JENKINS/Multi-Branch+Project+Plugin which may provide a better experience.

Vincent

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.

PaulD

unread,
Jan 7, 2016, 10:08:30 AM1/7/16
to jenkin...@googlegroups.com
That looks like a potential alternative solution. I will suggest that to my
team. We do like having a single build for all branches though as we have a
lot of builds and multiplying this by the number of branches isn't ideal.

It would still be nice to solve this problem in case I need to work on other
plugins in the future.



--
View this message in context: http://jenkins-ci.361315.n4.nabble.com/Trying-to-extend-FreeStyleProject-to-override-a-method-tp4788542p4788617.html

PaulD

unread,
Jan 8, 2016, 5:53:24 AM1/8/16
to jenkin...@googlegroups.com
Please could somebody just give me a straight answer as to what is needed to
add a new project type.



--
View this message in context: http://jenkins-ci.361315.n4.nabble.com/Trying-to-extend-FreeStyleProject-to-override-a-method-tp4788542p4788753.html

Jesse Glick

unread,
Jan 8, 2016, 11:28:30 AM1/8/16
to Jenkins Dev
On Fri, Jan 8, 2016 at 5:32 AM, PaulD <paul....@res-ltd.com> wrote:
> could somebody just give me a straight answer as to what is needed to add a new project type.

A lot of work and deep expertise in Jenkins core. I do not recommend
it. Anyway your described problem is exactly what multibranch projects
solve.

PaulD

unread,
Jan 8, 2016, 11:54:00 AM1/8/16
to jenkin...@googlegroups.com
Is there an easy way to migrate existing Free Style projects to be
multibranch projects?



--
View this message in context: http://jenkins-ci.361315.n4.nabble.com/Trying-to-extend-FreeStyleProject-to-override-a-method-tp4788542p4788829.html

Jesse Glick

unread,
Jan 8, 2016, 12:17:54 PM1/8/16
to Jenkins Dev
On Fri, Jan 8, 2016 at 11:33 AM, PaulD <paul....@res-ltd.com> wrote:
> Is there an easy way to migrate existing Free Style projects to be
> multibranch projects?

Not sure, perhaps the maintainer of that plugin can chime in.
Reply all
Reply to author
Forward
0 new messages