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

Uninstalling plugin corrupts config.xml and causes jobs to fail with java.lang.NullPointerException: Cannot invoke "java.util.Map.size()" because "map" is null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • core
    • None
    • Jenkins LTS 2.426.3

      I uninstalled the Build Monitor View due to the security issue reported in Jenkins Security Advisory 2024-03-06.

      However, the result was that jobs failed right at the start when the Controller attempts to checkout the pipeline script from git.

      Investigation shows that the plugin uninstall corrupted the main Jenkins config.xml.

      The failure in the job output looks like this:

      java.lang.NullPointerException: Cannot invoke "java.util.Map.size()" because "map" is null
      	at java.base/java.util.TreeMap.putAll(TreeMap.java:314)
      	at hudson.slaves.EnvironmentVariablesNodeProperty.buildEnvVars(EnvironmentVariablesNodeProperty.java:87)
      	at hudson.model.Computer.buildEnvironment(Computer.java:1205)
      	at hudson.model.Job.getEnvironment(Job.java:390)
      	at hudson.model.Run.getEnvironment(Run.java:2425)
      	at org.jenkinsci.plugins.workflow.job.WorkflowRun.getEnvironment(WorkflowRun.java:519)
      	at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:122)
      	at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:71)
      	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:311)
      	at hudson.model.ResourceController.execute(ResourceController.java:101)
      	at hudson.model.Executor.run(Executor.java:442)
      Finished: FAILURE
      

      I eventually tracked down the cause. The plugin uninstall corrupted the main Jenkins config.xml.

      Originally, the relevant part looked like this

        <globalNodeProperties>
          <hudson.slaves.EnvironmentVariablesNodeProperty>
            <envVars serialization="custom">
              <unserializable-parents/>
              <tree-map>
                <default>
                  <comparator class="java.lang.String$CaseInsensitiveComparator" reference="../../../../../../views/com.smartcodeltd.jenkinsci.plugins.buildmonitor.BuildMonitorView/jobNames/comparator"/>
                </default>
                <int>5</int>
                <string>PIP_REQUIRE_VIRTUALENV</string>
                <string>true</string>
                <string>AWS_ACCOUNT_ID</string>
                <string>111111111111</string>
                <string>AWS_ECR_REGISTRY_URL</string>
                <string>111111111111.dkr.ecr.us-east-1.amazonaws.com</string>
                <string>AWS_REGION</string>
                <string>us-east-1</string>
                <string>INSTALLATION_NAME</string>
                <string>Development</string>
              </tree-map>
            </envVars>
          </hudson.slaves.EnvironmentVariablesNodeProperty>
        </globalNodeProperties>
      

      After the plugin was uninstalled, the config was rewritten to look like this:

        <globalNodeProperties>
          <hudson.slaves.EnvironmentVariablesNodeProperty/>
          <int>5</int>
          <string>PIP_REQUIRE_VIRTUALENV</string>
          <string>true</string>
          <string>AWS_ACCOUNT_ID</string>
          <string>111111111111</string>
          <string>AWS_ECR_REGISTRY_URL</string>
          <string>111111111111.dkr.ecr.us-east-1.amazonaws.com</string>
          <string>AWS_REGION</string>
          <string>us-east-1</string>
          <string>INSTALLATION_NAME</string>
          <string>Development</string>
        </globalNodeProperties>
      

      It's quite clear the config has been mangled as a result of removing the plugin.
      I don't know if bad rewrite of the config is caused by a bug in the plugin, or in core.

            Unassigned Unassigned
            mwebber Matthew Webber
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: