ItemListener, onLocationChanged, modifying job property and saving. Result: after shutdown the modified property keeps the old value

18 views
Skip to first unread message

Ramón Rial

unread,
Jun 26, 2015, 10:54:23 AM6/26/15
to jenkin...@googlegroups.com
I want to be notified about Items changed locations, to modify some properties of jobs with the new value.
I use the ItemListener:

@Extension
public class ItemOperations extends ItemListener {

    public void onLocationChanged(Item item, String oldFullName, String newFullName) {
        System.out.println("ITEM location changed " + oldFullName + " " + newFullName + " " + item.getFullName());
        if (!item instanceof InheritanceProject) {
            return;
        }
        System.out.println("It is an InheritanceProject");

        InheritanceProject inherited = (InheritanceProject) item;
        InheritanceProject.clearBuffers(inherited);

        //And then fixing all named references
        for (InheritanceProject p : inherited.getProjectsMap().values()) {
            for (AbstractProjectReference ref : p.getParentReferences()) {
System.out.println("ParentReference " + ref.getName());
                if (ref.getName().equals(oldFullName)) {
                    ref.switchProject(inherited);
                }
            }
            for (AbstractProjectReference ref : p.compatibleProjects) {
System.out.println("compatibleProjects " + ref.getName());
                if (ref.getName().equals(oldFullName)) {
                    ref.switchProject(inherited);
                }
            }
            try {
                p.save();
                } catch (Exception e) {
                    e.printStackTrace();
                }
        }
    }

AbstractProjectReference is a property of the job, and I want change the project which points to (it is a String property). After switching the project (switchProject) all seems work right.
When I visit config page of the job I can see the new name, so it is OK.

Now I shutdown Jenkins, and I start it again.
I visit config page of the job again, but I see the old name, so it is wrong.

Why the configuration of the job was not saved to disk?

P.D:
I have tried with:
            try {
                p.save();
                } catch (Exception e) {
                    e.printStackTrace();
                }

too, and the same result.

Oleg Nenashev

unread,
Jul 5, 2015, 4:41:57 AM7/5/15
to jenkin...@googlegroups.com
Did you try to launch the code in the debugger? If it reaches the save() method, the project should be saved to XML file. You can check it contents on the disk. If the data is available there, the issue may be related to the loading procedure. More info is required to troubleshoot the issue w/o having a code of your plugin.


пятница, 26 июня 2015 г., 17:54:23 UTC+3 пользователь Ramón Rial написал:

Ramón Rial

unread,
Aug 25, 2015, 2:16:32 PM8/25/15
to jenkin...@googlegroups.com
Thank you, I've just seen today your answer, sorry.
It is working since 03-07-2015. It was a problem of misunderstood of the Jenkins Inheritance plugin, and now it is working.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/wB9m3BExwC8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/50f288d7-2aef-4a74-9131-8d6e0de8404b%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages