{"id":4964,"date":"2018-05-17T04:17:02","date_gmt":"2018-05-17T04:17:02","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=4964"},"modified":"2021-11-17T10:31:47","modified_gmt":"2021-11-17T10:31:47","slug":"how-to-execute-grovvy-script-remotely-on-jenkins-server","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/how-to-execute-grovvy-script-remotely-on-jenkins-server\/","title":{"rendered":"How to execute grovvy script remotely on Jenkins server?"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4975\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2018\/05\/jenkins-server-and-groovy.png\" alt=\"\" width=\"600\" height=\"350\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2018\/05\/jenkins-server-and-groovy.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2018\/05\/jenkins-server-and-groovy-300x175.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>A Jenkins Admin can execute groovy scripts remotely by sending an HTTP POST request to \/script\/ url or \/scriptText\/.<\/p>\n<p><strong>curl example via bash<\/strong><\/p>\n<p>[code]<br>\ncurl -d &#8220;script=&amp;lt;your_script_here&amp;gt;&#8221; https:\/\/jenkins\/script<br>\n# or to get output as a plain text result (no HTML)<br>\ncurl -d &#8220;script=&amp;lt;your_script_here&amp;gt;&#8221; https:\/\/jenkins\/scriptText<br>\n[\/code]<\/p>\n<p><strong>curl submitting groovy file via bash<\/strong><\/p>\n<p>[code]<br>\ncurl &#8211;data-urlencode &#8220;script=$(&amp;lt; .\/somescript.groovy)&#8221; https:\/\/jenkins\/scriptText<br>\n[\/code]<\/p>\n<p><strong>curl submitting groovy file providing username and password via bash<\/strong><\/p>\n<p>[code]<br>\ncurl &#8211;user &#8216;username:password&#8217; &#8211;data-urlencode &#8220;script=$(&amp;lt; .\/somescript.groovy)&#8221; https:\/\/jenkins\/scriptText<br>\n[\/code]<\/p>\n<p><strong>Jenkins CLI offers the possibility to execute groovy scripts remotely using groovy command or execute groovy interactivelly via groovysh.<\/strong><\/p>\n<p>[code]<br>\njava -jar jenkins-cli.jar -noCertificateCheck -s https:\/\/10.0.0.91\/ groovy disableEnableJobsMatchingPattern.groovy jobPattern=build_git_auto disableOrEnable=disable &#8211;username 12345 &#8211;password banana<br>\n[\/code]<\/p>\n<p><strong>Reference<\/strong><br>\nhttps:\/\/wiki.jenkins.io\/display\/JENKINS\/Jenkins+Script+Console<\/p>\n<p><iframe loading=\"lazy\" title=\"Jenkins World 2017: Mastering the Jenkins Script Console\" width=\"820\" height=\"461\" src=\"https:\/\/www.youtube.com\/embed\/qaUPESDcsGg?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p><iframe loading=\"lazy\" title=\"Jenkins Area Meetup - Hacking on Jenkins Internals - Jenkins Script Console\" width=\"820\" height=\"615\" src=\"https:\/\/www.youtube.com\/embed\/T1x2kCGRY1w?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_54417\"><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_44807\"  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_54417\"  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>A Jenkins Admin can execute groovy scripts remotely by sending an HTTP POST request to \/script\/ url or \/scriptText\/. curl example via bash [code] curl -d &#8220;script=&amp;lt;your_script_here&amp;gt;&#8221;&#8230; <\/p>\n","protected":false},"author":1,"featured_media":4975,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[42],"tags":[4928,145,819,278],"class_list":["post-4964","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jenkins","tag-grovvy","tag-jenkins","tag-remotely","tag-script"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4964","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=4964"}],"version-history":[{"count":4,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4964\/revisions"}],"predecessor-version":[{"id":25603,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/4964\/revisions\/25603"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/4975"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=4964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=4964"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=4964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}