Add a left hand side link for a job, powered by a particular BuildStep

89 views
Skip to first unread message

Kirill

unread,
Feb 10, 2015, 11:55:19 AM2/10/15
to jenkin...@googlegroups.com
Hi folks,

I created a plugin that contains a custom Builder. It is included in job XX on my Jenkins.

What I need is to add a link to the left-hand side of any build of any job in Jenkins, if it contains this build step. Say, if I create a job YY, this link has to appear on the left hand side when I go to the build details page (along with regular links like "Status", "Changes", etc.), as well as in job XX.

I used TransientActionFactory in the past, but I used it for a particular Build class. Not sure how to use it to work for any Build that has my Builder.

I made a naive attempt to do it like this, hoping that Jenkins will understand what I want (Builder is not Actionable, alas):

@Extension
public class MyLinkActionFactory extends TransientActionFactory<MyBuilder> {

    @Override
    public Class<MyBuilder> type() {
        return MyBuilder.class;
    }

    @Nonnull
    @Override
    public Collection<? extends Action> createFor(@Nonnull MyBuilder builder) {
            return Collections.singleton(new MyLinkAction("http://fullUrl"));
    }

}

public class MyLinkAction implements Action {
    private final String url;

    public MyLinkAction(String url) {
        this.url = url;
    }

    @Override
    public String getIconFileName() {
        return "/plugin/mystuff/images/24x24/ve.png";
    }

    @Override
    public String getDisplayName() {
        return "See the results";
    }

    @Override
    public String getUrlName() {
        return url;
    }
}

No surprize - it didn't work.
The only way out that I see is to use MyLinkActionFactory with any top-level item, but that will probably seriously slow down the Jenkins - and then somehow check whether it uses my Builder or not.:(

Any other more elegant solutions, people?

Regards,
Kirill.

Vincent Latombe

unread,
Feb 10, 2015, 1:39:54 PM2/10/15
to Jenkins Dev
Hi,

In the #perform, method of your Builder, create an instance of your Action and add it to the Build object.

In your case, I don't think you need to implement a TransientActionFactory.

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/c5da95d8-55bc-4464-92c3-ea34c270bb8a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kirill

unread,
Feb 11, 2015, 2:54:46 AM2/11/15
to jenkin...@googlegroups.com
Thanks a million, Vincent!
This worked like a charm.

Kirill.

вторник, 10 февраля 2015 г., 18:39:54 UTC пользователь Vincent Latombe написал:
Reply all
Reply to author
Forward
0 new messages