{"id":4962,"date":"2018-05-17T04:14:47","date_gmt":"2018-05-17T04:14:47","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=4962"},"modified":"2021-11-17T10:32:06","modified_gmt":"2021-11-17T10:32:06","slug":"how-to-run-execute-groovy-script-in-jenkins","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/how-to-run-execute-groovy-script-in-jenkins\/","title":{"rendered":"How to run\/execute groovy script in Jenkins?"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4978\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2018\/05\/groovy-script-in-Jenkins.png\" alt=\"\" width=\"600\" height=\"350\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2018\/05\/groovy-script-in-Jenkins.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2018\/05\/groovy-script-in-Jenkins-300x175.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>Here are the List of way using you can apply grovy code in Jenkins<\/p>\n<p><strong>Method -1: Groovy plugin<\/strong><br>\nThis plugin adds the ability to directly execute Groovy code.<br>\nMore info &#8211; https:\/\/wiki.jenkins.io\/display\/JENKINS\/Groovy+plugin<\/p>\n<p><strong>Method -2: Jenkins script console<\/strong><br>\nThe inbuilt script console is a very useful and powerful Jenkins extension and ideally suits certain types of tasks. This simple but powerful built-in web console allows you to run Groovy scripts on your Jenkins instance (or its slave nodes) from directly within the user interface, and is installed as standard.<\/p>\n<p>To access the console, either navigate to Manage Jenkins and then select Script Console, or simply append \/script to your Jenkins host and port, like this for example: http:\/\/jenkinshost:8080\/script<br>\nRunning Script Console on the master<br>\nThis feature can be accessed from &#8220;Manage Jenkins&#8221; &gt; &#8220;Script Console&#8221;. Or visit the sub-URL \/script on your Jenkins instance.<\/p>\n<p>Running Script Console on agents<br>\nVisit &#8220;Manage Jenkins&#8221; &gt; &#8220;Manage Nodes&#8221;. Select any node to view the status page. In the menu on the left, a menu item is available to open a &#8220;Script Console&#8221; on that specific agent.<\/p>\n<p>More info &#8211; https:\/\/wiki.jenkins.io\/display\/JENKINS\/Jenkins+Script+Console<\/p>\n<p><strong>Method -3: Scriptler Plugins<\/strong><br>\nScriptler allows you to store\/edit groovy scripts and execute it on any of the slaves\/nodes&#8230; no need to copy\/paste groovy code anymore.<br>\nMore Info &#8211; https:\/\/wiki.jenkins.io\/display\/JENKINS\/Scriptler+Plugin<\/p>\n<p><strong>Reference<\/strong><\/p>\n<p>https:\/\/wiki.jenkins.io\/display\/JENKINS\/Jenkins+Script+Console<\/p>\n<p><iframe loading=\"lazy\" title=\"Jenkins World 2017: Mastering the Jenkins Script Console\" width=\"760\" height=\"428\" src=\"https:\/\/www.youtube.com\/embed\/qaUPESDcsGg?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<p>&nbsp;<\/p>\n<p><iframe loading=\"lazy\" title=\"Jenkins Area Meetup - Hacking on Jenkins Internals - Jenkins Script Console\" width=\"760\" height=\"570\" src=\"https:\/\/www.youtube.com\/embed\/T1x2kCGRY1w?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_82805\"><iframe loading=\"lazy\"  id=\"_ytid_75612\"  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_82805\"  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 class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Here are the List of way using you can apply grovy code in Jenkins Method -1: Groovy plugin This plugin adds the ability to directly execute Groovy code. More info&#8230; <\/p>\n","protected":false},"author":1,"featured_media":4980,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[42],"tags":[437,4925,145,4926,4927],"class_list":["post-4962","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jenkins","tag-groovy","tag-groovy-plugin","tag-jenkins","tag-jenkins-script-console","tag-scriptler-plugins"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4962","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=4962"}],"version-history":[{"count":4,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4962\/revisions"}],"predecessor-version":[{"id":25604,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4962\/revisions\/25604"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/4980"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=4962"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=4962"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=4962"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}