{"id":133,"date":"2018-02-16T07:14:24","date_gmt":"2018-02-15T18:14:24","guid":{"rendered":"https:\/\/content.ronella.xyz\/apps\/wordpress\/?p=133"},"modified":"2018-02-16T07:14:24","modified_gmt":"2018-02-15T18:14:24","slug":"triggering-builds-remotely-with-jenkins-using-http-request-plugin","status":"publish","type":"post","link":"https:\/\/www.ronella.xyz\/?p=133","title":{"rendered":"Triggering builds remotely with Jenkins using HTTP Request plugin"},"content":{"rendered":"<p><b>Use Cases<\/b><\/p>\n<p>Lower Jenkins <i>(e.g. v1.x)<\/i> but requires later Jenkins (e.g. v2.x) functionality <i>(e.g. using git plugin which has some transitive dependencies which requires v2.x)<\/i>.<\/p>\n<p>For some reason , we just wanted a Jenkins server to delegate a task to another Jenkins server.<\/p>\n<p>You've created a script <i>(i.e. python, ruby, groovy, etc)<\/i> that will trigger a Jenkins task via HTTP protocol. This is not part of this document but the <b>Backend Jenkins Server<\/b> section is applicable.<\/p>\n<p><b>Backend Jenkins Server<\/b><\/p>\n<p>This is the server that will perform the task.<\/p>\n<p><b>Setting-up a role that can do remote build<\/b><\/p>\n<ol>\n<li>Click <b>Jenkins -&gt; Manage Jenkins -&gt; Manage and Assign Roles<\/b> entry and select <b>Manage Roles<\/b>.<\/li>\n<li>In the <b>Global roles<\/b>, add a new role <i>(e.g. remote_triggers)<\/i> that is allowed to trigger a task remotely.<\/li>\n<li>Once added enable the following:<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td>Overall<\/td>\n<td>Read<\/td>\n<\/tr>\n<tr>\n<td>Job<\/td>\n<td>Build<\/td>\n<\/tr>\n<tr>\n<td>Job<\/td>\n<td>Read<\/td>\n<\/tr>\n<tr>\n<td>Job<\/td>\n<td>Workspace<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>Example 1: Sample role configuration<\/b><\/p>\n<p>If we have <b>remote_triggers<\/b> as the new role, we have the following:<\/p>\n<p><a href=\"https:\/\/www.ronella.xyz\/wordpress\/wp-content\/uploads\/2018\/02\/http_rqst_mng_assign_roles.png\"><img loading=\"lazy\" class=\"alignnone wp-image-171\" src=\"https:\/\/www.ronella.xyz\/wordpress\/wp-content\/uploads\/2018\/02\/http_rqst_mng_assign_roles.png\" alt=\"\" width=\"659\" height=\"82\" \/><\/a><\/p>\n<p><b>Assigning a role to a user<\/b><\/p>\n<ol>\n<li>Click <b>Jenkins -&gt; Manage Jenkins -&gt; Manage and Assign Roles<\/b> entry and select <b>Assign Role<\/b>.<\/li>\n<li>In the <b>Global roles<\/b>, add a known Jenkins user.<\/li>\n<li>Once added assign the role.<\/li>\n<\/ol>\n<p><b>Example 2: Assign a role following Example 1.<\/b><\/p>\n<p>If the known user is <b>GwDevOpsDev<\/b>, we have the following:<\/p>\n<p><a href=\"https:\/\/www.ronella.xyz\/wordpress\/wp-content\/uploads\/2018\/02\/http_rqst_assign_roles.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-172\" src=\"https:\/\/www.ronella.xyz\/wordpress\/wp-content\/uploads\/2018\/02\/http_rqst_assign_roles.png\" alt=\"\" width=\"295\" height=\"181\" \/><\/a><\/p>\n<p><b>Setting-up the Build Triggers<\/b><\/p>\n<ol>\n<li>On the <b>Build Triggers<\/b> section, select the <b>Trigger builds remotely (e.g., from scripts)<\/b>.<\/li>\n<li>Provide an <b>Authentication Token<\/b>.<\/li>\n<\/ol>\n<p><i>Note: You can use <\/i><a href=\"https:\/\/www.guidgenerator.com\/\"><i>https:\/\/www.guidgenerator.com\/<\/i><\/a><i> just remove the hyphen for this.<\/i><\/p>\n<p>This will enable you to trigger the job remotely via HTTP Post using one of the following:<\/p>\n<p><b>Without Build Parameters<\/b><\/p>\n<pre>&lt;JENKINS_URL&gt;\/job\/&lt;URL_ENCODED_ITEM_NAME&gt;\/build?token=&lt;AUTHENTICATION_TOKEN&gt;<\/pre>\n<p><b>With Build Parameters<\/b><\/p>\n<pre>&lt;JENKINS_URL&gt;\/job\/&lt;URL_ENCODED_ITEM_NAME&gt;\/buildWithParameters?token=&lt;AUTHENTICATION_TOKEN&gt;<\/pre>\n<p><b>Example 3: Address to call a task remotely.<\/b><\/p>\n<p>If we have the following:<\/p>\n<pre>JENKINS_URL = <a href=\"http:\/\/d-51306g2.fmg.net:9080\">http:\/\/d-51306g2.fmg.net:9080<\/a>\r\nITEM_NAME=Statement Date Update to Saturday\r\nURL_ENCODED_ITEM_NAME=Statement%20Date%20Update%20to%20Saturday\r\nAUTHENTICATION_TOKEN=49dcf6a2164147b1871de70b40afef6f<\/pre>\n<p>The URL to call this job remotely with build parameters must be:<\/p>\n<pre>http:\/\/d-51306g2.fmg.net:9080\/job\/Statement%20Date%20Update%20to%20Saturday\/buildWithParameters?token=49dcf6a2164147b1871de70b40afef6f<\/pre>\n<p><b>User Facing Jenkins Server<\/b><\/p>\n<p>This is the Jenkins server that is normally use by the user to invoke tasks but the task is actually being done by a another Jenkins server.<\/p>\n<p><b>Pre-requisite<\/b><\/p>\n<ul>\n<li>HTTP Request Plugin<\/li>\n<\/ul>\n<p><b>Setting-up Credential to be used with the HTTP request.<\/b><\/p>\n<ol>\n<li>Click <b>Jenkins -&gt; Credentials<\/b> entry.<\/li>\n<li>Click the <b>global<\/b> store seen as follows:<a href=\"https:\/\/www.ronella.xyz\/wordpress\/wp-content\/uploads\/2018\/02\/http_rqst_scope.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-173\" src=\"https:\/\/www.ronella.xyz\/wordpress\/wp-content\/uploads\/2018\/02\/http_rqst_scope.png\" alt=\"\" width=\"348\" height=\"112\" \/><\/a><\/li>\n<li>Click <b>Add Credentials<\/b>.<\/li>\n<li>Set the <b>Kind<\/b> field to <b>Username with Password<\/b>.<\/li>\n<li>Set the <b>Scope<\/b> field to <b>Global<\/b> if not yet set.<\/li>\n<li>Set the <b>Username<\/b> field to the user that can to remote triggering configured on the backend Jenkins server <i>(e.g. <\/i><b><i>GwDevOpsDev<\/i><\/b><i> from Example 2)<\/i>.<\/li>\n<li>Set the <b>Password<\/b> field to a valid password.<\/li>\n<li>Set the <b>ID<\/b> field to something unique.<br \/>\n<i>Note: You can use <\/i><a href=\"https:\/\/www.guidgenerator.com\/\"><i>https:\/\/www.guidgenerator.com\/<\/i><\/a><i>\u00a0 for this.<\/i><\/li>\n<li>Click the <b>OK<\/b> button.<\/li>\n<\/ol>\n<p><b>Setting-up a New Item to Delegate Task to Backend Jenkins Server<\/b><\/p>\n<ol>\n<li>Click <b>New Item<\/b>.<\/li>\n<li>Provide an <b>Item name<\/b>.<\/li>\n<li>Select <b>Freestyle project<\/b>.<\/li>\n<li>Click the <b>OK<\/b> button.<\/li>\n<li>Click <b>Add build step-&gt; HTTP Request<\/b> entry.<\/li>\n<li>Fill-in the <b>URL<\/b> with the one configured in the backend Jenkins server <i>(e.g. <\/i><a href=\"http:\/\/d-51306g2.fmg.net:9080\/job\/Statement%20Date%20Update%20to%20Saturday\/buildWithParameters?token=49dcf6a2164147b1871de70b40afef6f\"><i>http:\/\/d-51306g2.fmg.net:9080\/job\/Statement%20Date%20Update%20to%20Saturday\/buildWithParameters?token=49dcf6a2164147b1871de70b40afef6f<\/i><\/a><i> from Example 3)<\/i><\/li>\n<li>Select <b>POST<\/b> for the <b>HTTP mode<\/b>.<\/li>\n<li>Click the <b>Advanced\u2026<\/b> button.<\/li>\n<li>In the <b>Authenticate<\/b> field select the set up from <b>Setting-up Credential to be used with the HTTP request<\/b> section earlier.<\/li>\n<li>Click the <b>Save<\/b> button.<\/li>\n<li>Now every time you click <b>Build now<\/b> it will complete immediately since the actual build will be done on the <b>Backend Jenkins Server<\/b>.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Use Cases Lower Jenkins (e.g. v1.x) but requires later Jenkins (e.g. v2.x) functionality (e.g. using git plugin which has some transitive dependencies which requires v2.x). For some reason , we just wanted a Jenkins server to delegate a task to another Jenkins server. You&#8217;ve created a script (i.e. python, ruby, groovy, etc) that will trigger [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/133"}],"collection":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=133"}],"version-history":[{"count":2,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/133\/revisions"}],"predecessor-version":[{"id":174,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/133\/revisions\/174"}],"wp:attachment":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}