Package jenkins.model

Class RunIdMigrator


  • @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class)
    public final class RunIdMigrator
    extends Object
    Converts legacy builds directories to the current format. There would be one instance associated with each Job, to retain ID → build# mapping. The Job.getBuildDir() is passed to every method call (rather than being cached) in case it is moved.
    • Constructor Detail

      • RunIdMigrator

        public RunIdMigrator()
    • Method Detail

      • created

        public void created​(File dir)
        Called when a job is first created. Just saves an empty marker indicating that this job needs no migration.
        Parameters:
        dir - as in Job.getBuildDir()
      • migrate

        public boolean migrate​(File dir,
                               @CheckForNull
                               File jenkinsHome)
        Perform one-time migration if this has not been done already. Where previously there would be a 2014-01-02_03-04-05/build.xml specifying <number>99</number> plus a symlink 99 → 2014-01-02_03-04-05, after migration there will be just 99/build.xml specifying <id>2014-01-02_03-04-05</id> and <timestamp>…</timestamp> according to local time zone at time of migration. Newly created builds are untouched. Does not throw IOException since we make a best effort to migrate but do not consider it fatal to job loading if we cannot.
        Parameters:
        dir - as in Job.getBuildDir()
        jenkinsHome - root directory of Jenkins (for logging only)
        Returns:
        true if migration was performed
      • findNumber

        public int findNumber​(@NonNull
                              String id)
        Look up a historical run by ID.
        Parameters:
        id - a nonnumeric ID which may be a valid Run.getId()
        Returns:
        the corresponding Run.number, or 0 if unknown
      • main

        public static void main​(String... args)
                         throws Exception
        Reverses the migration, in case you want to revert to the older format.
        Parameters:
        args - one parameter, $JENKINS_HOME
        Throws:
        Exception