[转载]优雅定时重启Jenkins

 

原文链接: https://stackoverflow.com/questions/21193072/need-to-restart-jenkins-service-programatically-on-a-schedule

 

 

 

需要先安装Groovy插件

 

If the above CLI method did not work (in my case it failed on: hudson.security.AccessDeniedException2: anonymous is missing the Overall/Read permission)

You can create a Groovy plugin build step and "Execute a system Groovy script":

import hudson.model.*;
Hudson.instance.doSafeRestart(null);

or the new Jenkins instance

import jenkins.model.*
Jenkins.instance.doSafeRestart(null);

Then, you can set this job to be triggered by schedule. For example, to restart Jenkins daily on midnight, set "Build periodically": H 00 * * *

 

posted on 2018-12-20 18:15  tuohai666  阅读(867)  评论(0编辑  收藏  举报

导航