{"id":1152,"date":"2023-08-31T13:25:22","date_gmt":"2023-08-31T07:55:22","guid":{"rendered":"https:\/\/www.openwriteup.com\/?page_id=1152"},"modified":"2024-01-11T16:52:55","modified_gmt":"2024-01-11T11:22:55","slug":"pipeline-project-installation-and-rest","status":"publish","type":"page","link":"https:\/\/www.openwriteup.com\/?page_id=1152","title":{"rendered":"Pipeline project installation and  rest"},"content":{"rendered":"<p>We have misc labs ,which covers use cases<\/p>\n<p>Lab1:<\/p>\n<p>Add the Jenkins users in sudoers<\/p>\n<pre>vi \/etc\/sudoers\r\n\r\njenkins ALL=(ALL) NOPASSWD: ALL<\/pre>\n<ol>\n<li>New Item&#8211;&gt;Ansibleproj&#8211;&gt;Pipeline&#8211;&gt;ok<\/li>\n<li>In pipeline script section, please run paste below code<\/li>\n<\/ol>\n<pre>pipeline {\r\nagent any\r\n stages {\r\n  stage('Checkout') {\r\n   steps {\r\n    \/\/ Checkout your Ansible playbook repository\r\n    git branch: 'main', url: ' https:\/\/github.com\/amitopenwriteup\/tfsource.git'\r\n   }\r\n  }\r\n  stage('Install Ansible') {\r\n   steps {\r\n    \/\/ Install Ansible on the Jenkins agent\r\n   sh 'sudo apt-get -y install ansible'\r\n  }\r\n }\r\n stage('Run Ansible Playbook') {\r\n   steps {\r\n   \/\/ Run the Ansible playbook\r\n  sh 'ansible-playbook -i inventory playbook.yaml'\r\n  }\r\n }\r\n}\r\n}<\/pre>\n<p><strong>Build now&#8211;&gt;check build history&#8211;&gt;Check console output<\/strong><\/p>\n<p>Incase, if it fails\u00a0 please check console output.<\/p>\n<pre>apt install python3-pip -y<\/pre>\n<p>Lab2: http request using pipeline<\/p>\n<p>Dashboard-&gt;Manage Jenkins&#8211;&gt;Plugin Manager&#8211;&gt;Available plugin&#8211;&gt;HTTP Request(install plugin without reboot<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins28.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1156\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins28-300x225.png\" alt=\"\" width=\"300\" height=\"225\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins28-300x225.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins28-700x525.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/jenkins28.png 726w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>New Item&#8211;&gt;name httpprojectpipeline&#8211;&gt;pipeline&#8211;&gt;ok<\/p>\n<p>Paste the below pipeline project<\/p>\n<pre>pipeline {\r\nagent any\r\n parameters {\r\n  string(name: 'param1', defaultValue: 'example-value', description: 'Parameter 1')\r\n }\r\nstages {\r\n  stage('HTTP Request') {\r\n   steps {\r\n    script {\r\n     def response = httpRequest \"http:\/\/httpbin.org\/response-headers?param1=${param1}\"\r\n     writeFile file: 'response.txt', text: response.content\r\n     println(\"Status: ${response.status}\")\r\n     println(\"Response: ${response.content}\")\r\n     println(\"Headers: ${response.headers}\")\r\n  }\r\n }\r\n}\r\n}\r\n}<\/pre>\n<p>Build now&#8211;&gt;check the build history<\/p>\n<ol>\n<li><strong>Parameters Declaration<\/strong>: The <code>parameters<\/code> block defines a single parameter named <code>param1<\/code>. This parameter is a string with a default value of <code>'example-value'<\/code>. It&#8217;s used to customize the HTTP request URL.<\/li>\n<li><strong>Stages Declaration<\/strong>: Inside the <code>stages<\/code> block, you have one stage named &#8216;HTTP Request&#8217;.<\/li>\n<li><strong>HTTP Request Stage<\/strong>: Within the &#8216;HTTP Request&#8217; stage, you have a <code>steps<\/code> block containing a <code>script<\/code> block. This is where the actual steps of the stage are defined.\n<ul>\n<li><strong>Script Block<\/strong>: Inside the <code>script<\/code> block, you&#8217;re making an HTTP GET request using the <code>httpRequest<\/code> step. The URL includes the value of the <code>param1<\/code> parameter as a query parameter.<\/li>\n<li><strong>Response Handling<\/strong>: The response from the HTTP request is stored in the <code>response<\/code> variable. The script then writes the response content to a file named <code>response.txt<\/code> using the <code>writeFile<\/code> step.<\/li>\n<li><strong>Print Statements<\/strong>: The script also prints out the status, response content, and headers of the HTTP response using <code>println<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have misc labs ,which covers use cases Lab1: Add the Jenkins users in sudoers vi \/etc\/sudoers jenkins ALL=(ALL) NOPASSWD: ALL New Item&#8211;&gt;Ansibleproj&#8211;&gt;Pipeline&#8211;&gt;ok In pipeline script section, please run paste below code pipeline { agent any stages { stage(&#8216;Checkout&#8217;) { steps { \/\/ Checkout your Ansible playbook repository git branch: &#8216;main&#8217;, url: &#8216; https:\/\/github.com\/amitopenwriteup\/tfsource.git&#8217; } [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_oct_exclude_from_cache":false,"footnotes":""},"class_list":["post-1152","page","type-page","status-publish","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/1152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1152"}],"version-history":[{"count":10,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/1152\/revisions"}],"predecessor-version":[{"id":1348,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/1152\/revisions\/1348"}],"wp:attachment":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}