jenkinsci/jenkins · error · IOException

Failed to set the timestamp of ${f} to ${timestamp}

Error message

Failed to set the timestamp of ${f} to ${timestamp}

What it means

Thrown by the Touch.invoke act when File.setLastModified(long) returns false, meaning the OS refused to update the file's last-modified timestamp. This wraps the raw boolean failure into an IOException propagated through FilePath.act(). Common causes: the file is read-only, on a filesystem that doesn't support mtime (e.g., some FAT variants, or the file is held open exclusively on Windows), or the timestamp value is out of the OS's supported range.

Source

Thrown at core/src/main/java/hudson/FilePath.java:1830

        act(new Touch(timestamp));
    }

    private static class Touch extends MasterToSlaveFileCallable<Void> {
        private final long timestamp;

        Touch(long timestamp) {
            this.timestamp = timestamp;
        }

            private static final long serialVersionUID = -5094638816500738429L;

            @Override
            public Void invoke(File f, VirtualChannel channel) throws IOException {
                if (!f.exists()) {
                    Files.newOutputStream(fileToPath(f)).close();
                }
                if (!f.setLastModified(timestamp))
                    throw new IOException("Failed to set the timestamp of " + f + " to " + timestamp);
                return null;
            }
    }

    private void setLastModifiedIfPossible(final long timestamp) throws IOException, InterruptedException {
        String message = act(new SetLastModified(timestamp));

        if (message != null) {
            LOGGER.warning(message);
        }
    }

    private static class SetLastModified extends MasterToSlaveFileCallable<String> {
        private final long timestamp;

        SetLastModified(long timestamp) {
            this.timestamp = timestamp;
        }

View on GitHub (pinned to 2e228ff40b)

Solutions

  1. Ensure the Jenkins process has write permission on the file and its parent directory.
  2. On Windows, close any process holding the file open before calling touch().
  3. Validate the timestamp is within the filesystem's supported range (FAT: 1980-01-01 to 2107-12-31).
  4. If mtime is not needed, catch IOException and log a warning instead of failing the build.

Example fix

// before
filePath.touch(timestamp);

// after — guard against unsupported mtime
try {
    filePath.touch(timestamp);
} catch (IOException e) {
    listener.getLogger().println("Warning: could not set timestamp: " + e.getMessage());
}
Defensive patterns

Strategy: try-catch

Validate before calling

long ts = timestamp;
// FAT supports 1980-01-01 to 2107-12-31
if (ts < 315532800000L || ts > 4133980799000L) {
    LOGGER.warning("Timestamp out of filesystem-supported range; touch may fail.");
}
if (!f.canWrite()) {
    LOGGER.warning("File is not writable; setLastModified will likely fail: " + f);
}

Try / catch

try {
    filePath.setLastModifiedIfPossible(timestamp);
} catch (IOException e) {
    // Non-fatal: timestamp is cosmetic in most build contexts
    LOGGER.log(Level.WARNING, "Could not set timestamp on {0}", filePath);
}

Prevention

When it happens

Trigger: Calling FilePath.touch(long timestamp) on a path whose target file has a last-modified time that cannot be changed — file is locked, read-only, or the timestamp is negative/out of epoch range for the filesystem.

Common situations: Windows with a file open in another process (exclusive lock), files on network-mounted shares (SMB/NFS) with restricted permissions, FAT/exFAT volumes that reject pre-1980 or far-future timestamps, or containerized builds where the file owner differs from the Jenkins process UID.

Related errors


AI-assisted analysis of jenkinsci/jenkins@2e228ff40b (2026-08-14). Data as JSON: /api/errors/437d47fc8a9408fb. Report an issue: GitHub.