<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Edmar Barros on Medium]]></title>
        <description><![CDATA[Stories by Edmar Barros on Medium]]></description>
        <link>https://medium.com/@edmarbarros?source=rss-d72fdbaf46b0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zGounpMJPHxs0hFm1yj8Pw.jpeg</url>
            <title>Stories by Edmar Barros on Medium</title>
            <link>https://medium.com/@edmarbarros?source=rss-d72fdbaf46b0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 06:30:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@edmarbarros/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[CI/CD Pipeline with Jenkins and AWS S3]]></title>
            <link>https://faun.pub/ci-cd-pipeline-with-jenkins-and-aws-s3-c08a3656d381?source=rss-d72fdbaf46b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/c08a3656d381</guid>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Edmar Barros]]></dc:creator>
            <pubDate>Fri, 01 Feb 2019 17:12:00 GMT</pubDate>
            <atom:updated>2021-02-10T01:27:42.249Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*ivG4n7Eg9cNTU1HcnrRHFg.png" /><figcaption><a href="https://jenkins.io/artwork/">https://jenkins.io/artwork/</a> by <a href="https://twitter.com/ks_nenasheva">Ksenia Nenasheva</a></figcaption></figure><h3>CI/CD Pipeline with Jenkins on AWS</h3><h4>Jenkins CI/CD made easy! Automate your deployment process, save time and reduce risks. Because automation is a friend, not a nightmare.</h4><p>Manual tests and deployments can lead to multiple errors that a well defined CI/CD pipeline can avoid while testing your application, inspect the code quality, deploying and… I could enumerate many others aspects of why CI/CD is a must have but let me drive you through the setup process instead!</p><h3>But, what is Jenkins?</h3><blockquote>Jenkins is a self-contained, open source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software. — <a href="https://jenkins.io/doc/">https://jenkins.io/doc/</a></blockquote><p>Jenkins is one of the most popular Open Source CI tools on the market. It offers support for multiples <a href="https://en.wikipedia.org/wiki/Version_control">SCM</a> and many other 3rd party apps via its <a href="https://plugins.jenkins.io/">plugins</a>. And, with concepts like <a href="https://jenkins.io/doc/book/pipeline-as-code/">Pipeline-as-Code</a>, the entire build process can be checked into a SCM and versioned like the rest of your code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Z7yvuBKdJ_XL5b3KtZBdcA.jpeg" /><figcaption>Pipe whaat? Pipeline!</figcaption></figure><h3>… What is a Pipeline?</h3><blockquote>A <em>continuous delivery (CD) pipeline</em> is an automated expression of your process for getting software from version control right through to your users and customers.— <a href="https://jenkins.io/doc/book/pipeline/">https://jenkins.io/doc/book/pipeline/</a></blockquote><p>The Pipeline defines a set of action that Jenkins will execute in order to test, build and deploy your application. You can define Stages per branches, run commands in parallel, define environment variables and much more.</p><p>In this article I’m going to define a Pipeline to test and deploy a static web application into AWS S3.</p><h3><strong>Setup the build environment</strong></h3><p>For our build environment we’ll launch an Amazon EC2 instance using the Amazon Linux 2 AMI, install and configure the required packages. Make sure that the security group you select for your instance allows traffic on ports TCP/22 and TCP/80 so you will be able to connect to you instance via SSH and access it via browser using its DNS.</p><p><strong>Install and configure Jenkins and required packages</strong></p><p>Connect to your instance using your private key:</p><pre>$ ssh -i &quot;path-to-key/key.pem&quot; ec2-user@&lt;instance-name&gt;.&lt;instance-region&gt;.compute.amazonaws.com</pre><p>First, let’s update the repositories and install Docker and Git:</p><pre>$ sudo yum update -y<br>$ sudo yum install -y docker git java-1.8.0-openjdk</pre><p>Add the Jenkins repository and install Jenkins from there:</p><pre>$ sudo wget -O /etc/yum.repos.d/jenkins.repo <a href="http://pkg.jenkins.io/redhat/jenkins.repo">http://pkg.jenkins.io/redhat/jenkins.repo</a><br>$ sudo rpm --import <a href="https://pkg.jenkins.io/redhat/jenkins.io.key">https://pkg.jenkins.io/redhat/jenkins.io.key</a><br>$ sudo yum install jenkins -y<br>$ sudo usermod -aG root jenkins # Add jenkins to the root group</pre><p>To allow Jenkins to build our Docker images, we need to add the <em>jenkins </em>user to the <em>docker </em>group:</p><pre># Add Jenkins and current user to the Docker group<br>$ sudo usermod -aG docker $USER<br>$ sudo usermod -aG docker jenkins</pre><p>Add the Jenkins and Docker services to start on boot and start both services:</p><pre># Add Jenkins and Docker to startup<br>$ sudo chkconfig jenkins on<br>$ sudo chkconfig docker on<br>$ sudo chkconfig --list</pre><pre># Start Jenkins and Docker as a service<br>$ sudo service jenkins start<br>$ sudo service docker start</pre><p>As Jenkins typically uses port TCP/8080, we’ll configure <em>iptables</em> routing rules to redirect the traffic:</p><pre>$ sudo iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT<br>$ sudo iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT</pre><pre>$ sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080</pre><p>I’m not covering the usage of SSL certificates, to use HTTPS you need to include rules to redirect traffic for port 443:</p><pre>$ sudo iptables -I INPUT 1 -p tcp --dport 8443 -j ACCEPT<br>$ sudo iptables -I INPUT 1 -p tcp --dport 443 -j ACCEPT</pre><pre>$ sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8443</pre><p>You can find more about SSL certificates on this article from <a href="https://medium.com/u/3c6acfb1e50d">Paul Lessing</a>:</p><p><a href="https://medium.com/@P_Lessing/single-page-apps-on-aws-part-1-hosting-a-website-on-s3-3c9871f126">Single-Page Apps on AWS, Part 1: Hosting a Website on S3</a></p><p>At this point you should be able to see the Jenkins home page using the public DNS name of your EC2 instance(e.g. ec2–&lt;ec2-public-ip-address&gt;.compute-1.amazonaws.com):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*-tuSyBfeKPx8Ng8aC2YGXA.jpeg" /><figcaption>Jenkins Setup — Administrator password</figcaption></figure><p>Get the password from the indicated file:</p><pre>$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword</pre><p>Install the recommended plugins and create an Admin account in the following steps.</p><p>At this point you should be able to login an see the following page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*OrY8i6HDx1bVknc7Zkfr-g.png" /><figcaption>Jenkins home page</figcaption></figure><p><strong>Install Jenkins Plugins</strong></p><p>At the Jenkins home page on the left menu select <em>Manage Jenkins -&gt; Manage Plugins</em> select the tab <em>Available</em> and search for the following plugins:</p><ul><li><a href="https://jenkins.io/projects/blueocean/">Blue Ocean</a> - New Jenkins UI</li><li><a href="https://plugins.jenkins.io/pipeline-aws">Pipeline AWS</a> - AWS Integration</li></ul><p><strong>Create the Pipeline AWS Jenkins Credential</strong></p><p>At the Jenkins home page on the left menu click at <em>Credentials-&gt;System,</em> select the scope <em>global</em> and at the left menu again <em>Add Credential:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ub2sf5c1TvfEBHDmmqBGpQ.png" /><figcaption>Create AWS Credential</figcaption></figure><p>Provide the <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html">AWS IAM Credentials</a> to allow Jenkins Pipeline AWS Plugin to access your S3 Bucket. At the above image, insert the created <em>Access Key ID</em> and the <em>Secret Access Key</em>. You can define and ID that will be used at the Jenkinsfile configuration as the following example:</p><pre>withAWS(region:&#39;&lt;your-bucket-region&gt;&#39;,credentials:&#39;&lt;Jenkins-Credential-ID-AWS&gt;&#39;) {</pre><p>The &lt;Jenkins-Credential-ID&gt; is the ID of the credential you’ve just created.</p><p><strong>Blue Ocean Pipeline</strong></p><p>Jenkins Blue Ocean UI makes it easier to create and configure a new pipeline.</p><ol><li>Create a <a href="https://jenkins.io/doc/book/blueocean/creating-pipelines/">new pipeline</a> and select GitHub as repository</li><li>Enter a <a href="https://github.blog/2013-05-16-personal-api-tokens/">Personal Access Token</a> from GitHub to allow Jenkins to access and scan your repositories.</li><li>Follow the instructions and the Blue Ocean will look for a <a href="https://jenkins.io/doc/book/pipeline/jenkinsfile/">Jenkinsfile</a>, if does not exists Blue Ocean allows you to define a new file and configure the Pipeline.</li></ol><p>If you create a Pipeline with Blue Ocean it will commit the Jenkinsfile to your repository and it will have a structure similar to the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c27b4a3265cbc9be25075463da91e6c6/href">https://medium.com/media/c27b4a3265cbc9be25075463da91e6c6/href</a></iframe><p>The above Jenkinsfile has a pipeline as you can see at the following image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mHTgMTBsyBrYrZdNMworHg.png" /><figcaption>Jenkins Blue Ocean Pipeline</figcaption></figure><p>The Pipeline above uses a docker agent to test the application and to create the final build files. The Deployment stage will remove the files from a given S3 bucket, upload the new build files and send an email to inform that a new deployment was successfully completed.</p><p>One thing to note is at the <em>agent</em> definition it used a port range is used to avoid the job to fail in case a given port is already in use</p><p><strong>Setup the GitHub Webhook</strong></p><p>A WebHook is an HTTP callback: an HTTP POST that occurs when something happens; a simple event-notification via HTTP POST. A GitHub Webhook allows Jenkins to subscribe to repository events like Pushes and Pull Requests.</p><p>The Webhook will send a POST request to your Jenkins instance to notify that an action was triggered(PR, Push, Commit…) and it should run a new job over the code changes.</p><p>Go to you repository <strong>Settings,</strong> select <strong>Webhooks </strong>on the left menu and click on the button <strong>Add webhook.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IrZbIXaE_M_ct6r8Ts-1eg.png" /><figcaption>GitHub Repository Settings — Webhooks</figcaption></figure><p>Set the <strong>Payload URL</strong> to http://&lt;your-jenkins-instance&gt;/github-webkook/ and the <strong>Content type</strong> to <em>application/json</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N-JYL-nE27gk01EHCGEEsA.png" /><figcaption>GitHub Repository Settings — Create a Webhook</figcaption></figure><p>Select the individual events that you want to be used to trigger a new Jenkins build. I recommend to select <em>Pushes</em> and <em>Pull Requests.</em></p><p>After that you will be able to see a similar message after a PR is created and it passes Jenkins validation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pfqaik6Nq2OmnFX_5S9-qQ.png" /><figcaption>GitHub Pull Request Status</figcaption></figure><p><strong>Create the S3 Bucket</strong></p><p>At your AWS console go to <em>Services</em> -&gt; <em>S3</em> and click the Create bucket button. Choose you bucket name and region, untick both options under the Manage public bucket polices for this bucket and finish the bucket creation. Open the bucket <em>Properties</em>, turn on the <em>Static website hosting</em> and define the <em>index.html</em> to point to your entry file like the following image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*smMjgNmiC9KpI1gDLi0Swg.png" /><figcaption>AWS S3 Bucket Properties — Static website hosting</figcaption></figure><p>To use a custom domain name you need to create a second bucket and under <em>Static website hosting</em> select the <em>Redirect requests</em> option. That option allows you to define the domain that will be used to access the hosting bucket. Bear in mind that this secondary bucket will use a <a href="https://en.wikipedia.org/wiki/HTTP_301">HTTP status code 301</a> to redirect the requests.</p><p>At this point you should be able to access your website using you custom domain you via the bucket</p><pre><a href="http://jenkins-dashboard-citruslab.s3-website-us-west-2.amazonaws.com/">http://&lt;bucket-name&gt;.s3-website-&lt;region&gt;.amazonaws.com</a></pre><h3>Conclusion</h3><p>This process has multiple pros and cons and I would like to drop my two cents on this and highlight a couple of them.</p><p><strong>Pros</strong></p><ul><li>Cheaper process with a good performance of a CDN to deliver static content.</li><li>AWS handles the traffic so scalability won’t be an issue.</li></ul><p><strong>Cons</strong></p><ul><li>Cache! Updates may take a while to be propagated as it has to wait the cache to expire.</li><li>Server side rendering. Bots and crawler won’t be able to get any metadata.</li></ul><p>Despite the cache, that can be handled by setting to the <em>index.html</em> a short <em>maxAge</em>, this solution can be considered robust and sustainable as it takes advantages of multiple AWS resources to make its availability and scalability to follow high standards as it is required nowadays.</p><p><em>Thanks for reading!</em></p><p>Feel free to reach me out on <a href="https://twitter.com/edmarbarros_">Twitter</a>, <a href="http://www.linkedin.com/in/edmarbarros">Linkedin</a>, and here on Medium.</p><h3><strong>References</strong></h3><p>Lessing, Paul. ‘Single-Page Apps on AWS, Part 1: Hosting a Website on S3’. <em>Medium</em>, 16 Apr. 2018, <a href="https://medium.com/@P_Lessing/single-page-apps-on-aws-part-1-hosting-a-website-on-s3-3c9871f126">https://medium.com/@P_Lessing/single-page-apps-on-aws-part-1-hosting-a-website-on-s3-3c9871f126</a>.</p><p>‘Personal API Tokens’. <em>The GitHub Blog</em>, 17 May 2013, <a href="https://github.blog/2013-05-16-personal-api-tokens/">https://github.blog/2013-05-16-personal-api-tokens/</a>.</p><p>‘Pipeline’. <em>Pipeline</em>, <a href="https://jenkins.io/doc/book/pipeline/index.html">https://jenkins.io/doc/book/pipeline/index.html</a>. Accessed 28 Jan. 2019.</p><p>‘Pipeline as Code’. <em>Pipeline as Code</em>, <a href="https://jenkins.io/doc/book/pipeline-as-code/index.html">https://jenkins.io/doc/book/pipeline-as-code/index.html</a>. Accessed 28 Jan. 2019.</p><p><em>Solution 1: Vanilla CI/CD Pipeline — Jenkins on AWS</em>. <a href="https://docs.aws.amazon.com/aws-technical-content/latest/jenkins-on-aws/solution-1-vanilla-cicd-pipeline.html">https://docs.aws.amazon.com/aws-technical-content/latest/jenkins-on-aws/solution-1-vanilla-cicd-pipeline.html</a>. Accessed 28 Jan. 2019.</p><p>‘Webhooks’. <em>GitHub Developer</em>, <a href="https://developer.github.com/webhooks/">https://developer.github.com/webhooks/</a> Accessed 28 Jan. 2019.</p><h3>Learn more</h3><p>Code, Quick. ‘Top Tutorials To Learn Jenkins CI For Testing Automation’. <em>Medium</em>, 4 June 2018, <a href="https://medium.com/quick-code/top-tutorials-to-learn-jenkins-ci-for-testing-automation-93c7ac068f66">https://medium.com/quick-code/top-tutorials-to-learn-jenkins-ci-for-testing-automation-93c7ac068f66</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*Piks8Tu6xUYpF4DU" /></figure><p><strong>Join our community Slack and read our weekly Faun topics ⬇</strong></p><figure><a href="https://www.faun.dev/join/?utm_source=medium.com%2Ffaun&amp;utm_medium=medium&amp;utm_campaign=faunmediumbanner"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oSdFkACJxs5iy1oR" /></a></figure><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c08a3656d381" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/ci-cd-pipeline-with-jenkins-and-aws-s3-c08a3656d381">CI/CD Pipeline with Jenkins and AWS S3</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>