背景
需要对jenkins做迁移,但是老的jenkins需要保留一段时间,先把老的jenkins所有job禁用掉
禁用多分支pipeline
找到Manage Jenkins=>Script Console 输入下面的脚本
import hudson.model.* disableChildren(Hudson.instance.items) def disableChildren(items) { for (item in items) { if (item.class.canonicalName == 'com.cloudbees.hudson.plugins.folder.Folder') { disableChildren(((com.cloudbees.hudson.plugins.folder.Folder) item).getItems()) } else if (item.class.canonicalName != 'org.jenkinsci.plugins.workflow.job.WorkflowJob') { item.disabled=true item.save() println(item.name) } } }
禁用所有pipeline
import hudson.model.* disableChildren(Hudson.instance.items) def disableChildren(items) { for (item in items) { if (item.class.canonicalName == 'com.cloudbees.hudson.plugins.folder.Folder') { disableChildren(((com.cloudbees.hudson.plugins.folder.Folder) item).getItems()) } else { item.disabled=true item.save() println(item.name) } } }
参考
https://wiki.jenkins.io/display/JENKINS/Disable+all+jobs
还没有评论,来说两句吧...