public static @ Nonnull String getLastExecVersion ( ) { File lastExecVersionFile = getLastExecVersionFile ( ) ; if ( lastExecVersionFile . exists ( ) ) { try { String version = FileUtils . readFileToString ( lastExecVersionFile ) ; // JENKINS-37438 blank will force the setup // wizard regardless of current state of the system if ( StringUtils . isBlank ( version ) ) { return FORCE_NEW_INSTALL_VERSION . toString ( ) ; } return version ; } catch ( IOException e ) { LOGGER . log ( SEVERE , "Unexpected Error. Unable to read " + lastExecVersionFile . getAbsolutePath ( ) , e ) ; LOGGER . log ( WARNING , "Unable to determine the last running version (see error above). Treating this as a restart. No plugins will be updated." ) ; return getCurrentExecVersion ( ) ; } } else { // Backward compatibility. Use the last version stored in the top level config.xml. // Going to read the value directly from the config.xml file Vs hoping that the // Jenkins startup sequence has moved far enough along that it has loaded the // global config. It can't load the global config until well into the startup // sequence because the unmarshal requires numerous objects to be created e.g. // it requires the Plugin Manager. It happens too late and it's too risky to // change how it currently works. File configFile = getConfigFile ( ) ; if ( configFile . exists ( ) ) { try { String lastVersion = XMLUtils . getValue ( "/hudson/version" , configFile ) ; if ( lastVersion . length ( ) > 0 ) { LOGGER . log ( Level . FINE , "discovered serialized lastVersion {0}" , lastVersion ) ; return lastVersion ; } } catch ( Exception e ) { LOGGER . log ( SEVERE , "Unexpected error reading global config.xml" , e ) ; } } return NEW_INSTALL_VERSION . toString ( ) ; } }
Get the last saved Jenkins instance version .