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

CLI update-job and POSTing config.xml cannot remove properties

      The custom workspace of a Jenkins job cannot be removed by the CLI using update-job.

      Steps to reproduce:
      1. Have a job with a custom workspace.
      2. Remove the custom workspace using the Jenkins java CLI (having a second job without the custom workspace and doing <cli> -get-job <second job> | <cli> update-job <job> is how we encountered this problem).
      3. Note that the config.xml of the job no longer references a custom workspace.
      4. Open the job in the Web GUI. Note that the custom workspace is there, and a save of the job without doing any updates will put the custom workspace configuration back into the config.xml file for the job.

      Bottom line - to remove the custom workspace, one either needs to do it via the web GUI, or do a restart of the Jenkins instance after doing it via the CLI.

      Side note: the " and some other characters are save differently when updating a job via the CLI vs. the Web GUI.

      Example: double quotes " will be changed to '"' in config.xml through CLI method.

          [JENKINS-21017] CLI update-job and POSTing config.xml cannot remove properties

          additional-identities plugins has nothing to do with the ticket.
          It's a CLI issue. And a bit of a GUI issue since it's not being updated properly.

          Sagi Sinai-Glazer added a comment - additional-identities plugins has nothing to do with the ticket. It's a CLI issue. And a bit of a GUI issue since it's not being updated properly.

          Jesse Glick added a comment -

          AbstractItem.updateByXml does not support undefining a field (customWorkspace in this case). I am not even sure how it would be done; XStream does not seem to directly support this.

          Jesse Glick added a comment - AbstractItem.updateByXml does not support undefining a field ( customWorkspace in this case). I am not even sure how it would be done; XStream does not seem to directly support this.

          Daniel Beck added a comment -

          Related Cloudbees issue for their Template plugin experiencing the same problem:
          https://rm.cloudbees.com/issues/1346

          Daniel Beck added a comment - Related Cloudbees issue for their Template plugin experiencing the same problem: https://rm.cloudbees.com/issues/1346

          The Job DSL plugin is also experiencing this problem: JENKINS-26825

          Daniel Spilker added a comment - The Job DSL plugin is also experiencing this problem: JENKINS-26825

          Jesse Glick added a comment -

          Some clever soul needs to dig around in XStream internals and make hudson.util.XStream2.unmarshal null out fields when root != null.

          Jesse Glick added a comment - Some clever soul needs to dig around in XStream internals and make hudson.util.XStream2.unmarshal null out fields when root != null .

          Jesse Glick added a comment -

          For CloudBees reference: CJP-1429

          Jesse Glick added a comment - For CloudBees reference: CJP-1429

          Andrew Bayer added a comment -

          So I probably have no idea what I'm talking about and my brain is oozing out my ears from trying to figure this out, but could we do some special-casing in RobustReflectionConverter to specifically grab any JobPropertys (when deserializing a Job descendant) or immediate class fields (for anything descending from AbstractItem) that show up in the deserialization process, and remove any that are set in the original but don't show up in the deserialization?

          Andrew Bayer added a comment - So I probably have no idea what I'm talking about and my brain is oozing out my ears from trying to figure this out, but could we do some special-casing in RobustReflectionConverter to specifically grab any JobPropertys (when deserializing a Job descendant) or immediate class fields (for anything descending from AbstractItem) that show up in the deserialization process, and remove any that are set in the original but don't show up in the deserialization?

          Stephen Connolly added a comment - - edited

          Stephen Connolly added a comment - - edited My attempt to fix this: https://github.com/jenkinsci/jenkins/pull/2736

          Code changed in jenkins
          User: Stephen Connolly
          Path:
          core/src/main/java/hudson/util/RobustReflectionConverter.java
          core/src/test/java/hudson/util/XStream2Test.java
          http://jenkins-ci.org/commit/jenkins/c62f4f753d16210b67ec381b9e5d1d60145594d8
          Log:
          JENKINS-21017 When unmarshalling into an existing object, reset missing fields

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Stephen Connolly Path: core/src/main/java/hudson/util/RobustReflectionConverter.java core/src/test/java/hudson/util/XStream2Test.java http://jenkins-ci.org/commit/jenkins/c62f4f753d16210b67ec381b9e5d1d60145594d8 Log: JENKINS-21017 When unmarshalling into an existing object, reset missing fields

          Code changed in jenkins
          User: Oleg Nenashev
          Path:
          core/src/main/java/hudson/XmlFile.java
          core/src/main/java/hudson/model/AbstractItem.java
          core/src/main/java/hudson/model/View.java
          core/src/main/java/hudson/util/ReflectionUtils.java
          core/src/main/java/hudson/util/XStream2.java
          core/src/test/java/hudson/util/XStream2Test.java
          test/src/test/java/hudson/model/AbstractProjectTest.java
          test/src/test/java/hudson/model/ViewTest.java
          http://jenkins-ci.org/commit/jenkins/16042bd57bc3e7bc0544b3a4da5e0f79dfa5087b
          Log:
          Merge pull request #3196 from jglick/unmarshal-JENKINS-21017

          JENKINS-21017 When unmarshalling into an existing object, reset missing fields

          Compare: https://github.com/jenkinsci/jenkins/compare/0ac93deba0d1...16042bd57bc3

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Oleg Nenashev Path: core/src/main/java/hudson/XmlFile.java core/src/main/java/hudson/model/AbstractItem.java core/src/main/java/hudson/model/View.java core/src/main/java/hudson/util/ReflectionUtils.java core/src/main/java/hudson/util/XStream2.java core/src/test/java/hudson/util/XStream2Test.java test/src/test/java/hudson/model/AbstractProjectTest.java test/src/test/java/hudson/model/ViewTest.java http://jenkins-ci.org/commit/jenkins/16042bd57bc3e7bc0544b3a4da5e0f79dfa5087b Log: Merge pull request #3196 from jglick/unmarshal- JENKINS-21017 JENKINS-21017 When unmarshalling into an existing object, reset missing fields Compare: https://github.com/jenkinsci/jenkins/compare/0ac93deba0d1...16042bd57bc3

            jglick Jesse Glick
            royzeng Roy Zeng
            Votes:
            16 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated:
              Resolved: