Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-25175

ItemListener event not fired when user updates projects configuration using REST API

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • core
    • jenkins LTS ver 1.565.3
      Ubuntu precise

      The jenkins ItemListener does not fire events when user updates project configurations using the REST API. Events do get fired when user makes changes from the UI though.

      Steps to repro:
      I am using the python-jenkins library (https://pypi.python.org/pypi/python-jenkins) to update my jobs which does all operations using the jenkins rest API.

      1. Create a project
      2. Update the project configuration using the REST api. I tried changing the 'concurrentBuild' and 'assignNode' configurations.
      3. check the job configuration in the UI to make sure it has been updated.

      Note - The job configuration does get updated with the change but no events called from ItemListener. I would expect the ItemListener.onUpdated() event to fire.

      This is the XML that was used for updating the job:

      <?xml version="1.0" encoding="utf-8"?>
      <project>
      <actions/>
      <description></description>
      <keepDependencies>false</keepDependencies>
      <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
      <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
      <concurrentBuild>false</concurrentBuild>
      <assignedNode>centos</assignedNode>
      <canRoam>false</canRoam>
      <properties/>
      <scm class="hudson.scm.NullSCM"/>
      <builders>
      <hudson.tasks.Shell>
      <command>echo my test</command>
      </hudson.tasks.Shell>
      </builders>
      <publishers/>
      <buildWrappers/>
      </project>

          [JENKINS-25175] ItemListener event not fired when user updates projects configuration using REST API

          Khai Do created issue -
          Khai Do made changes -
          Description Original: The jenkins ItemListener does not fire events when user updates project labels. I would expect the onUpdated event to fire.

          Steps to repro:
          1. create a new project
          2. select 'Restrict where this project can be run' box and add a label that matches a slave the save the project.
          3. now configure the same project and change the label to match a different slave then save the project.

          Note1 - No events are fired.
          Note2 - If on step #3, you un-select the option 'Restrict where this project can be run' (thereby removing the label) then save an event does get called.
          New: The jenkins ItemListener does not fire events when user updates project configurations using the REST API. Events do get fired when user makes changes from the UI though.

          Steps to repro:
          I am using the python-jenkins library (https://pypi.python.org/pypi/python-jenkins) to update my jobs which does all operations using the jenkins rest API.

          1. Create a project
          2. Update the project configuration using the REST api. I tried changing the 'concurrentBuild' and 'assignNode' configurations.

          Note - No events fired from ItemListener. I would expect the ItemListener.onUpdated() event to fire.

          This is the XML that was used for updating the job:

          <?xml version="1.0" encoding="utf-8"?>
          <project>
            <actions/>
            <description></description>
            <keepDependencies>false</keepDependencies>
            <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
            <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
            <concurrentBuild>false</concurrentBuild>
            <assignedNode>centos</assignedNode>
            <canRoam>false</canRoam>
            <properties/>
            <scm class="hudson.scm.NullSCM"/>
            <builders>
              <hudson.tasks.Shell>
                <command>echo my test</command>
              </hudson.tasks.Shell>
            </builders>
            <publishers/>
            <buildWrappers/>
          </project>

          Khai Do made changes -
          Description Original: The jenkins ItemListener does not fire events when user updates project configurations using the REST API. Events do get fired when user makes changes from the UI though.

          Steps to repro:
          I am using the python-jenkins library (https://pypi.python.org/pypi/python-jenkins) to update my jobs which does all operations using the jenkins rest API.

          1. Create a project
          2. Update the project configuration using the REST api. I tried changing the 'concurrentBuild' and 'assignNode' configurations.

          Note - No events fired from ItemListener. I would expect the ItemListener.onUpdated() event to fire.

          This is the XML that was used for updating the job:

          <?xml version="1.0" encoding="utf-8"?>
          <project>
            <actions/>
            <description></description>
            <keepDependencies>false</keepDependencies>
            <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
            <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
            <concurrentBuild>false</concurrentBuild>
            <assignedNode>centos</assignedNode>
            <canRoam>false</canRoam>
            <properties/>
            <scm class="hudson.scm.NullSCM"/>
            <builders>
              <hudson.tasks.Shell>
                <command>echo my test</command>
              </hudson.tasks.Shell>
            </builders>
            <publishers/>
            <buildWrappers/>
          </project>

          New: The jenkins ItemListener does not fire events when user updates project configurations using the REST API. Events do get fired when user makes changes from the UI though.

          Steps to repro:
          I am using the python-jenkins library (https://pypi.python.org/pypi/python-jenkins) to update my jobs which does all operations using the jenkins rest API.

          1. Create a project
          2. Update the project configuration using the REST api. I tried changing the 'concurrentBuild' and 'assignNode' configurations.
          3. check the job configuration in the UI to make sure it has been updated.

          Note - The job configuration does get updated with the change but no events called from ItemListener. I would expect the ItemListener.onUpdated() event to fire.

          This is the XML that was used for updating the job:

          <?xml version="1.0" encoding="utf-8"?>
          <project>
            <actions/>
            <description></description>
            <keepDependencies>false</keepDependencies>
            <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
            <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
            <concurrentBuild>false</concurrentBuild>
            <assignedNode>centos</assignedNode>
            <canRoam>false</canRoam>
            <properties/>
            <scm class="hudson.scm.NullSCM"/>
            <builders>
              <hudson.tasks.Shell>
                <command>echo my test</command>
              </hudson.tasks.Shell>
            </builders>
            <publishers/>
            <buildWrappers/>
          </project>

          Daniel Beck added a comment -

          Not sure this is a bug. Still, workaround is present, so reducing priority: Implement SaveableListener.onChange.

          Please do a bit more effort before filing an issue. Like making sure the description matches reality. Your other issue was a complete waste of time.

          Daniel Beck added a comment - Not sure this is a bug. Still, workaround is present, so reducing priority: Implement SaveableListener.onChange . Please do a bit more effort before filing an issue. Like making sure the description matches reality. Your other issue was a complete waste of time.
          Daniel Beck made changes -
          Priority Original: Major [ 3 ] New: Minor [ 4 ]

          Antoine Musso added a comment -

          > Not sure this is a bug. Still, workaround is present, so reducing priority: Implement SaveableListener.onChange.

          It seems to be a bug to me, the web interface and the REST API behave completely differently. The issue at hand is that changes made via the web interface triggers ItemListener events based on fields that have been changed. On the other hand, the REST API is just a way to upload a new config file, so it uses the SaveableListener which is rather dumb and fire an event which has the whole new XML file. Ie SaveableListener is a gross generalization while ItemListener is thiner.

          Would it make sense to have the REST API to fire the ItemListener events as well? It might not be doable though since the only data available is the whole config file and I think the events need finer informations (such as a Label object, not a whole config file). Another way would be to have the SaveableListener events build in core to inject the new conf to the code that handles configuration changes for the web interface, thus reusing all the existing logic that ends up triggering ItemListener events.

          To say it otherwise: I would expect uploading a config file to behave exactly the same as doing a change via the web interface form.

          Antoine Musso added a comment - > Not sure this is a bug. Still, workaround is present, so reducing priority: Implement SaveableListener.onChange. It seems to be a bug to me, the web interface and the REST API behave completely differently. The issue at hand is that changes made via the web interface triggers ItemListener events based on fields that have been changed. On the other hand, the REST API is just a way to upload a new config file, so it uses the SaveableListener which is rather dumb and fire an event which has the whole new XML file. Ie SaveableListener is a gross generalization while ItemListener is thiner. Would it make sense to have the REST API to fire the ItemListener events as well? It might not be doable though since the only data available is the whole config file and I think the events need finer informations (such as a Label object, not a whole config file). Another way would be to have the SaveableListener events build in core to inject the new conf to the code that handles configuration changes for the web interface, thus reusing all the existing logic that ends up triggering ItemListener events. To say it otherwise: I would expect uploading a config file to behave exactly the same as doing a change via the web interface form.

          Daniel Beck added a comment -

          The issue at hand is that changes made via the web interface triggers ItemListener events based on fields that have been changed. On the other hand, the REST API is just a way to upload a new config file, so it uses the SaveableListener which is rather dumb and fire an event which has the whole new XML file. Ie SaveableListener is a gross generalization while ItemListener is thiner. … I think the events need finer informations (such as a Label object, not a whole config file).

          ItemListener does not tell you which properties were changed. it tells you only the Item that changed, while SaveableListener tells you the Saveable that changed (same object as the Item in this case) and the config XML. I don't see why you think the former includes more specific information.

          I would expect uploading a config file to behave exactly the same as doing a change via the web interface form.

          Where does this expectation come from? POSTing to config.xml simply provides a new config file, containing often undocumented, internal data structure representations, which will then be loaded. The other processes a submitted form, can transform inputs, etc. The inputs are completely different, the processing is (necessarily) completely different, so any expectation of these behaving in any way alike has no basis in reality.

          Would it make sense to have the REST API to fire the ItemListener events as well?

          Possibly.

          Daniel Beck added a comment - The issue at hand is that changes made via the web interface triggers ItemListener events based on fields that have been changed. On the other hand, the REST API is just a way to upload a new config file, so it uses the SaveableListener which is rather dumb and fire an event which has the whole new XML file. Ie SaveableListener is a gross generalization while ItemListener is thiner. … I think the events need finer informations (such as a Label object, not a whole config file). ItemListener does not tell you which properties were changed. it tells you only the Item that changed, while SaveableListener tells you the Saveable that changed (same object as the Item in this case) and the config XML. I don't see why you think the former includes more specific information. I would expect uploading a config file to behave exactly the same as doing a change via the web interface form. Where does this expectation come from? POSTing to config.xml simply provides a new config file, containing often undocumented, internal data structure representations, which will then be loaded. The other processes a submitted form, can transform inputs, etc. The inputs are completely different, the processing is (necessarily) completely different, so any expectation of these behaving in any way alike has no basis in reality. Would it make sense to have the REST API to fire the ItemListener events as well? Possibly.
          R. Tyler Croy made changes -
          Workflow Original: JNJira [ 159084 ] New: JNJira + In-Review [ 179857 ]

            Unassigned Unassigned
            zaro Khai Do
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: