Shutting down my plugin on Jenkins shutdown

68 views
Skip to first unread message

Joachim Nilsson

unread,
Nov 4, 2015, 3:22:45 AM11/4/15
to Jenkins Developers
Hi

How do I detect Jenkins shut-down in my plug-in so I can close down connections and thread pools in a nice way?

Regards,
Joachim

Baptiste Mathus

unread,
Nov 4, 2015, 3:38:38 AM11/4/15
to jenkin...@googlegroups.com
Hi Joachim,

In general, for that kind of question, the way to go is to search https://wiki.jenkins-ci.org/display/JENKINS/Extension+points for something matching your needs.
Quickly greping myself, though I never did that very thing, maybe implementing either hudson.lifecycle.Lifecycle or hudson.model.RestartListener may be of interest I guess.

My 2 cents

--
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/32bb6310-6e0b-4d0c-9ddb-9e40c021c642%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Baptiste <Batmat> MATHUS - http://batmat.net
Sauvez un arbre,
Mangez un castor !

Baptiste Mathus

unread,
Nov 4, 2015, 3:41:14 AM11/4/15
to jenkin...@googlegroups.com
Btw, wondering if Jenkins does/could/should support @PostConstruct & @PreDestroy annotations. Might be a good way to handle disconnections and so on when components are teared down while shutting down.

Joachim Nilsson

unread,
Nov 4, 2015, 4:54:17 AM11/4/15
to Jenkins Developers, m...@batmat.net
+1 for the annotations.
Thanks for the input. I did find the Lifecycle extension before I asked but that was not the right place.
RestartListener could work though even if I do not want to veto any restart from my plugin.

Regards,
Joachim

Daniel Beck

unread,
Nov 4, 2015, 6:21:36 AM11/4/15
to jenkin...@googlegroups.com

On 04.11.2015, at 09:22, Joachim Nilsson <jocce....@gmail.com> wrote:

> How do I detect Jenkins shut-down in my plug-in so I can close down connections and thread pools in a nice way?

Plugin#stop() could help with this.

Joachim Nilsson

unread,
Nov 4, 2015, 7:35:45 AM11/4/15
to Jenkins Developers, m...@beckweb.net
Thanks!

Joachim Nilsson

unread,
Nov 4, 2015, 7:38:19 AM11/4/15
to Jenkins Developers
I think I found the intended location: ItemListener

    /**
     * @since 1.446
     *      Called at the begenning of the orderly shutdown sequence to
     *      allow plugins to clean up stuff
     */
    public void onBeforeShutdown() {
    }

which is called from Jenkins from e.g. doSafeExit():
    public void cleanUp() {
        for (ItemListener l : ItemListener.all())
            l.onBeforeShutdown();
Reply all
Reply to author
Forward
0 new messages