{"id":4960,"date":"2018-05-17T04:10:33","date_gmt":"2018-05-17T04:10:33","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=4960"},"modified":"2021-11-17T10:32:23","modified_gmt":"2021-11-17T10:32:23","slug":"database-of-groovy-script-for-jenkins-automation","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/database-of-groovy-script-for-jenkins-automation\/","title":{"rendered":"Database of Groovy Script for Jenkins Automation"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-4987\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2018\/05\/groovy-script-jenkins-automation-1.png\" alt=\"\" width=\"603\" height=\"352\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2018\/05\/groovy-script-jenkins-automation-1.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2018\/05\/groovy-script-jenkins-automation-1-300x175.png 300w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><\/p>\n<p>Here are the list of Groovy Script which can be used in Jenkins to automate the JOBs and CI process. Please add your list in the comment sections as well.<\/p>\n<p><strong>Main Source &#8211;\u00a0<\/strong><\/p>\n<ul>\n<li>https:\/\/github.com\/scmgalaxy\/jenkins-groovy-script-example<\/li>\n<li>https:\/\/github.com\/cloudbees\/jenkins-scripts<\/li>\n<li>https:\/\/wiki.jenkins.io\/display\/JENKINS\/Jenkins+Script+Console<\/li>\n<li>https:\/\/pghalliday.com\/jenkins\/groovy\/sonar\/chef\/configuration\/management\/2014\/09\/21\/some-useful-<\/li>\n<li>jenkins-groovy-scripts.html<\/li>\n<li>https:\/\/github.com\/cloudbees\/jenkins-scripts<\/li>\n<li>https:\/\/github.com\/jenkinsci\/jenkins-scripts<\/li>\n<li>https:\/\/gist.github.com\/dnozay\/e7afcf7a7dd8f73a4e05<\/li>\n<li>https:\/\/github.com\/samrocketman\/jenkins-bootstrap-shared<\/li>\n<li>https:\/\/github.com\/samrocketman\/jenkins-script-console-scripts<\/li>\n<\/ul>\n<p><strong>Example\u00a0Groovy Script\u00a0<\/strong><\/p>\n<ul class=\"childpages-macro conf-macro output-block\" data-hasbody=\"false\" data-macro-name=\"children\">\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Activate+Chuck+Norris+Plugin\" target=\"_blank\" rel=\"noopener\">Activate Chuck Norris Plugin<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script activates Chuck Norris plugin for all jobs in your Jenkins server<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Add+a+Maven+Installation%2C+Tool+Installation%2C+Modify+System+Config\" target=\"_blank\" rel=\"noopener\">Add a Maven Installation, Tool Installation, Modify System Config<\/a><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Add+a+new+label+to+slaves+meeting+a+condition\" target=\"_blank\" rel=\"noopener\">Add a new label to slaves meeting a condition<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script shows how to alter the slave nodes&#8217; label membership. In this case we create a new label if the existing label contains a string. It has been tested from the Jenkins command window.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Add+notification+plugin+to+every+job\" target=\"_blank\" rel=\"noopener\">Add notification plugin to every job<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script will add the Notification Plugin to every job.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Allow+broken+build+claiming+on+every+jobs\" target=\"_blank\" rel=\"noopener\">Allow broken build claiming on every jobs<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">With the following simple script, you can activate the option on every jobs of your server in just one go.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Batch-Update+Mercurial+branch+that+is+checked+out\" target=\"_blank\" rel=\"noopener\">Batch-Update Mercurial branch that is checked out<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">Updates for multiple jobs which branch will be checked out from Hg<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Bulk+rename+projects\" target=\"_blank\" rel=\"noopener\">Bulk rename projects<\/a><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Change+JVM+Options+in+all+Maven+tasks+of+Freestyle+Jobs\" target=\"_blank\" rel=\"noopener\">Change JVM Options in all Maven tasks of Freestyle Jobs<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script find all Maven Tasks registered in freestyle jobs and replace JVM Options by a new value.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Change+publish+over+SSH+configuration\" target=\"_blank\" rel=\"noopener\">Change publish over SSH configuration<\/a><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Change+SCMTrigger+for+each+project+to+disable+during+the+night+and+the+week-end\" target=\"_blank\" rel=\"noopener\">Change SCMTrigger for each project to disable during the night and the week-end<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script lets you easily change all jobs running every minutes so that it gets disabled between 21:00 and 07:00 and on Saturday and Sunday.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Change+Version-Number+in+SVN-path\" target=\"_blank\" rel=\"noopener\">Change Version-Number in SVN-path<\/a><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Clone+all+projects+in+a+View\" target=\"_blank\" rel=\"noopener\">Clone all projects in a View<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script enumerates all projects belonging to a specific view and clones them.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Convert+standard+mail+notifications+to+use+the+Mail-Ext+Publisher+plugin\" target=\"_blank\" rel=\"noopener\">Convert standard mail notifications to use the Mail-Ext Publisher plugin<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script replace mail notifications in all projects by Mail-Ext publisher plugin and re-uses existing recipients.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Delete+.tmp+files+left+in+workspace-files\" target=\"_blank\" rel=\"noopener\">Delete .tmp files left in workspace-files<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This scripts deletes all the tmp files left in workspace-files directory after the build. On windows servers, this seems pretty common so we run this script on daily basis.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Delete+workspace+for+all+disabled+jobs\" target=\"_blank\" rel=\"noopener\">Delete workspace for all disabled jobs<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">Deletes the workspace for all disabled jobs to save space<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Disable+all+jobs\" target=\"_blank\" rel=\"noopener\">Disable all jobs<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script disables all jobs in your Jenkins server<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Display+Information+About+Nodes\" target=\"_blank\" rel=\"noopener\">Display Information About Nodes<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This scripts displays a bunch of information about all the slave nodes.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Display+job+parameters\" target=\"_blank\" rel=\"noopener\">Display job parameters<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This scripts displays the parameters for all the jobs along with their default values (if applicable).<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Display+jobs+group+by+the+build+steps+they+use\" target=\"_blank\" rel=\"noopener\">Display jobs group by the build steps they use<\/a><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/pages\/viewpage.action?pageId=67569264\" target=\"_blank\" rel=\"noopener\">Display list of projects that were built more than 1 day ago.<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script to display list of projects that were built more than 1 day ago.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Display+mail+notifications+recipients\" target=\"_blank\" rel=\"noopener\">Display mail notifications recipients<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script displays for all jobs the list of mail recipients used for notifications.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Display+monitors+status\" target=\"_blank\" rel=\"noopener\">Display monitors status<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">Jenkins uses monitors to validate various behaviors. If you dismiss one, Jenkins will never propose you to reactivate it. This script allows you to check the status of all monitors and to reactive them.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Display+timer+triggers\" target=\"_blank\" rel=\"noopener\">Display timer triggers<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This scripts displays the timer triggers for all the jobs in order to better arrange them.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Display+Tools+Location+on+All+Nodes\" target=\"_blank\" rel=\"noopener\">Display Tools Location on All Nodes<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script can help to get Jenkins tools localtion on all your slaves<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Enable+Timestamper+plugin+on+all+jobs\" target=\"_blank\" rel=\"noopener\">Enable Timestamper plugin on all jobs<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">With the following simple script, you can activate the option on every jobs of your server in just one go.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Failed+Jobs\" target=\"_blank\" rel=\"noopener\">Failed Jobs<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This scripts displays a list of all failed jobs. Addon: restart them.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Find+builds+currently+running+that+has+been+executing+for+more+than+N+seconds\" target=\"_blank\" rel=\"noopener\">Find builds currently running that has been executing for more than N seconds<\/a><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Grant+Cancel+Permission+for+user+and+group+that+have+Build+permission\" target=\"_blank\" rel=\"noopener\">Grant Cancel Permission for user and group that have Build permission<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script will go through all groups and users in both Global security and per job security settings.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Invalidate+Jenkins+HTTP+sessions\" target=\"_blank\" rel=\"noopener\">Invalidate Jenkins HTTP sessions<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script can monitor and invalidate HTTP sessions if there are many open ones on your server.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Manually+run+log+rotation+on+all+jobs\" target=\"_blank\" rel=\"noopener\">Manually run log rotation on all jobs<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">Runs log rotation on all jobs to free space<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Monitor+and+Restart+Offline+Slaves\" target=\"_blank\" rel=\"noopener\">Monitor and Restart Offline Slaves<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script can monitor and restart offline nodes if they are not disconnected manually.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Monitoring+Scripts\" target=\"_blank\" rel=\"noopener\">Monitoring Scripts<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">Several scripts to display data about http sessions, threads, memory, JVM or MBeans, when using the Monitoring plugin.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Parameterized+System+Groovy+script\" target=\"_blank\" rel=\"noopener\">Parameterized System Groovy script<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script will demonstrate how to get parameters in a system groovy script.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Preselect+username+in+Maven+Release+Build\" target=\"_blank\" rel=\"noopener\">Preselect username in Maven Release Build<\/a><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Printing+a+list+of+credentials+and+their+IDs\" target=\"_blank\" rel=\"noopener\">Printing a list of credentials and their IDs<\/a><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Remove+all+disabled+modules+in+Maven+jobs\" target=\"_blank\" rel=\"noopener\">Remove all disabled modules in Maven jobs<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">To remove all disabled modules in Maven jobs<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Remove+Deployed+Artifacts+Actions\" target=\"_blank\" rel=\"noopener\">Remove Deployed Artifacts Actions<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script is used to remove the Deployed Artifacts list that is uselessly stored for each build by the Artifact Deployer Plugin.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Remove+Git+Plugin+BuildsByBranch+BuildData\" target=\"_blank\" rel=\"noopener\">Remove Git Plugin BuildsByBranch BuildData<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script is used to remove the static list of BuildsByBranch that is uselessly stored for each build by the Git Plugin.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Set+GitBlitRepositoryBrowser+with+custum+settings+on+all+repos\" target=\"_blank\" rel=\"noopener\">Set GitBlitRepositoryBrowser with custum settings on all repos<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This scripts allows to update the repo browser. Can be adapted to any other browser, not only gitblit.<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Update+maven+jobs+to+use+the+post+build+task+to+deploy+artifacts\" target=\"_blank\" rel=\"noopener\">Update maven jobs to use the post build task to deploy artifacts<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script updates all maven jobs having a deploy goal by install and activate the post build step to deploy artifacts at the end of the build<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Update+SVN+Browser\" target=\"_blank\" rel=\"noopener\">Update SVN Browser<\/a><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Wipe+out+workspaces+of+all+jobs\" target=\"_blank\" rel=\"noopener\">Wipe out workspaces of all jobs<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">This script wipes out the workspaces of all jobs on your Jenkins server<\/span><\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Wipe+workspaces+for+a+set+of+jobs+on+all+nodes\" target=\"_blank\" rel=\"noopener\">Wipe workspaces for a set of jobs on all nodes<\/a>\u00a0\u2014\u00a0<span class=\"smalltext\">The script wipes workspaces of certain jobs on all nodes<\/span><\/li>\n<\/ul>\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_31908\"><figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube epyt-figure\"><div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\"  id=\"_ytid_82434\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_31908\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Here are the list of Groovy Script which can be used in Jenkins to automate the JOBs and CI process. Please add your list in the comment sections as well. Main Source &#8211;\u00a0 https:\/\/github.com\/scmgalaxy\/jenkins-groovy-script-example https:\/\/github.com\/cloudbees\/jenkins-scripts https:\/\/wiki.jenkins.io\/display\/JENKINS\/Jenkins+Script+Console https:\/\/pghalliday.com\/jenkins\/groovy\/sonar\/chef\/configuration\/management\/2014\/09\/21\/some-useful- jenkins-groovy-scripts.html https:\/\/github.com\/cloudbees\/jenkins-scripts https:\/\/github.com\/jenkinsci\/jenkins-scripts https:\/\/gist.github.com\/dnozay\/e7afcf7a7dd8f73a4e05 https:\/\/github.com\/samrocketman\/jenkins-bootstrap-shared https:\/\/github.com\/samrocketman\/jenkins-script-console-scripts Example\u00a0Groovy Script\u00a0 Activate Chuck Norris Plugin\u00a0\u2014\u00a0This script activates Chuck Norris plugin for&#8230;<\/p>\n","protected":false},"author":1,"featured_media":4983,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[42],"tags":[437,145],"class_list":["post-4960","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jenkins","tag-groovy","tag-jenkins"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4960","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=4960"}],"version-history":[{"count":8,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4960\/revisions"}],"predecessor-version":[{"id":25606,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4960\/revisions\/25606"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/4983"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=4960"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=4960"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=4960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}