Jenkins uptime - how long since last restart

前端 未结 3 1222
迷失自我
迷失自我 2021-02-09 03:34

Is it possible to see how long a Jenkins instance/master has been running?

I\'ve tried looking around in \"Manage Jenkins\" but can\'t find it there. I know I could log

3条回答
  •  闹比i
    闹比i (楼主)
    2021-02-09 03:52

    There has been an Uptime class in Jenkins Core since a long time (Jenkins 1.538). So using the same principle with the script console, the code can be made more readable and robust:

    println "Jenkins has been started " + (ExtensionList.lookupSingleton(Uptime.class).uptime / 1000 / 60 ) + " minutes ago"
    

    Which will show, e.g.:

    Jenkins has been started 175.8678166667 minutes ago

    Note: ExtensionList.lookupSingleton was introduced in Jenkins 2.87. So if you're using an earlier version, use ExtensionList.lookup(Uptime.class).get(0) instead.

提交回复
热议问题