<?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 Parshuram Gurav on Medium]]></title>
        <description><![CDATA[Stories by Parshuram Gurav on Medium]]></description>
        <link>https://medium.com/@parshuramgurav5?source=rss-d6739239ff65------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*alKxGaG0j2RX3YZX</url>
            <title>Stories by Parshuram Gurav on Medium</title>
            <link>https://medium.com/@parshuramgurav5?source=rss-d6739239ff65------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 04:47:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@parshuramgurav5/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 For Serverless Framework In GCP]]></title>
            <link>https://medium.com/@parshuramgurav5/ci-cd-for-serverless-framework-in-gcp-ef91b97efe49?source=rss-d6739239ff65------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef91b97efe49</guid>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[jenkins-pipeline]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[serverless-architecture]]></category>
            <dc:creator><![CDATA[Parshuram Gurav]]></dc:creator>
            <pubDate>Sat, 10 Dec 2022 08:20:40 GMT</pubDate>
            <atom:updated>2022-12-10T08:20:40.623Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Implementing CI/CD pipeline in Jenkins server for deploying serverless applications on GCP using serverless framework</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PjnCOa9C8qJcdEVaM3hypA.png" /></figure><p><strong>“Serverless”</strong> is the buzzword these days everyone wants to move or build their application to a serverless architecture due to its multiple advantages and a serverless framework helps us to achieve our serverless goals.</p><p>In this article, we will be looking at how we can create the CI/CD pipeline in the Jenkins server to deploy our code in Cloud Functions. I will be adding the <a href="https://github.com/parshuramgurav/serverless-framework-test">Github</a> link where you can find all the code.</p><h4>What is a serverless framework?</h4><p>It helps you develop, deploy, troubleshoot and secure your serverless applications with less overhead and cost.</p><p>The <a href="https://www.serverless.com/framework/docs">Serverless Framework</a> also consists of an open-source CLI that offers structure, automation and best practices out-of-the-box, allowing you to focus on building sophisticated, event-driven, serverless architectures, comprised of <a href="https://www.serverless.com/framework/docs/providers/google/guide/intro#functions">Functions</a> and <a href="https://www.serverless.com/framework/docs/providers/google/guide/intro#events">Events</a>. Together, they provide you with full serverless application lifecycle management.</p><p>Serverless Framework is termed as a very specialized infrastructure as a code tool but it is different from Ansible and Terraform because using this you can only create a serverless application.</p><p>It is cloud agnostic in nature, which means it can be used with multiple cloud vendors like AWS, GCP, and Azure.</p><p>For framework <a href="https://www.serverless.com/framework/docs/providers/google/guide/installation">installation</a> and <a href="https://www.serverless.com/framework/docs/providers/google/guide/quick-start">quick start</a>, you can follow their documentation page.</p><h4>How does a serverless framework works?</h4><p>Every serverless application will consist of 2 main files. First is <strong>serverless.yaml</strong> which is the configuration file where all the functions and events reside and there is a second file called <strong>index.js</strong> which is where your application logic is written.</p><p>Now if you are deploying it on GCP then the serverless framework converts the serverless.yaml file into a cloud deployment manager template which is a native IAC tool in GCP for resources creation and if the same is deployed on AWS the serverless framework will convert serverless.yaml file into the AWS CloudFormation template and that template will be used to create all the resources which were mentioned inside the serverless.yaml file.</p><h4>Steps</h4><ul><li><strong><em>Jenkins installation</em></strong></li><li><strong><em>Configuring Jenkins Server For Running serverless framework</em></strong></li><li><strong><em>Creating credentials</em></strong></li><li><strong><em>Adding credentials in Jenkins</em></strong></li><li><strong><em>Creating Jenkins jobs</em></strong></li><li><strong><em>Changing the jenkinsfile</em></strong></li></ul><h4><strong>Jenkins Installation</strong></h4><p>We are using Jenkins for our CICD pipeline but this can be replaced with Gitlab, based on your requirements.</p><p>Create a VM of CentOS 7 and <a href="https://www.jenkins.io/doc/book/installing/linux/#red-hat-centos">install Jenkins</a> server on that VM.</p><p>After following all the installation steps you can access the Jenkins webpage using the server&#39;s IP address.</p><p>Once you can access the Jenkins webpage add all the recommended plugins and set the admin user.</p><p>Note: Jenkins services run on port 8080 so please make sure that the firewall rules of the server are also opened to access Jenkins webpage from the browser.</p><h4><strong>Configuring Jenkins server for running serverless framework</strong></h4><p>To run all the bash commands under the Jenkins pipeline as sudo you need to add a Jenkins user inside the sudoers file.</p><ul><li>Open sudoers files of the Jenkins server.</li></ul><pre>vim /etc/sudoers</pre><ul><li>Add the below line inside it</li></ul><pre>jenkins ALL= NOPASSWD: ALL</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*blilRi1sI3Fim4g3" /></figure><p>For serverless installation, you first need to install <a href="https://nodejs.org/en/">node.js</a> &amp; npm on your Jenkins server.</p><ul><li>Run the below commands to install node js and npm</li></ul><pre>yum install nodejs -y &amp;&amp; yum install npm -y</pre><ul><li>You can verify that node.js is installed successfully by running the following command on a terminal.</li></ul><pre>node --version</pre><p>You should see the corresponding Node version number printed out.</p><ul><li>Also, you can check the npm version by running the below command.</li></ul><pre>npm --version</pre><ul><li>Next, install the serverless framework via npm. Open up a terminal and type.</li></ul><pre>npm install -g serverless</pre><ul><li>To check the version of serverless that you have installed.</li></ul><pre>serverless --version</pre><p>Note: If you are using your custom image for Jenkins installation then you need to install gcloud SDK installed on your Jenkins server. Also, try to use the latest version of node and npm.</p><h4><strong>Creating Credentials</strong></h4><p>We need to create a new service account which would be used by Jenkins to authenticate GCP at the time of pipeline deployment.</p><ul><li>Go to the <a href="https://console.cloud.google.com/"><strong>Google Cloud Console</strong></a><strong>.</strong></li><li>Choose the <strong>project</strong> that you are working on from the top drop-down.</li><li>Click <strong>IAM &amp; admin</strong> menu on left-sidebar.</li><li>Then click <strong>Service accounts</strong> on left-sidebar.</li><li>Click <strong>CREATE SERVICE ACCOUNT</strong> button on the top.</li><li>Input your Service account name and the Service account ID will be generated automatically for you. Change it if you wish to.</li><li>Click <strong>Create</strong> button.</li><li>Add <strong>Deployment Manager Editor, Storage Admin, Logging Admin, Cloud Functions Developer roles.</strong></li><li>Click on <strong>Done</strong>.</li></ul><p>Once a service account is created we also have to create a <strong>JSON secret</strong> <strong>key.</strong></p><ul><li>Go to the <a href="https://console.cloud.google.com/"><strong>Google Cloud Console</strong></a><strong>.</strong></li><li>Choose the <strong>project</strong> that you are working on from the top drop-down.</li><li>Click <strong>IAM &amp; admin</strong> menu on left-sidebar.</li><li>Then click <strong>Service accounts</strong> on left-sidebar.</li><li>Use the filter to search for the newly created service account, then click on the Email of the service account.</li><li>Click on <strong>KEYS</strong> from the top.</li><li>Then click on <strong>Add Key.</strong></li><li>Now, click on <strong>Create New Key.</strong></li></ul><h4><strong>Adding Credentials in Jenkins</strong></h4><p>It will help Jenkins to access the GCP resources using the service account which we created in the previous step.</p><ul><li>Go to Jenkins’s webpage</li><li>Click on <strong>Dashboard</strong> on the top left side.</li><li>Go under <strong>Manage Jenkins.</strong></li><li>Then Click on <strong>Manage Credentials.</strong></li><li>Click on <strong>Add</strong> <strong>Credentials.</strong></li><li>Select the <strong>Secret file</strong> under the <strong>Kind</strong> section.</li><li>Click on Choose <strong>file</strong> and then select the <strong>secret JSON key</strong> which we generated from the previous step.</li><li>Add <em>gcloud-creds</em> as <strong>ID</strong>, you can give any name but same you have to add it in Jenkinsfile.</li><li>Then click on <strong>Create.</strong></li></ul><h4><strong>Creating Jenkins jobs</strong></h4><p>You can clone my <a href="https://github.com/parshuramgurav/serverless-framework-test">GitHub</a> code in your account and then try it out from your GitHub account.</p><p>To create a new job click on <strong>New Item</strong> on the top left side of the dashboard.</p><p>Entire any name of your choice and then select <strong>Pipeline</strong> and then click <strong>OK.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PZ6jMHAdWv3ekEwg" /></figure><p>You will be automatically moved to the configuration page of the newly created pipeline.</p><p>Then select <strong>Pipeline script from SCM</strong> under the pipeline <strong>Definition</strong> section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MxJFQZM6_8fNLIiM" /></figure><p>Add your <strong>GitHub Repository URL</strong> then select <strong>Credentials </strong>if your repo is private in nature. If it is a public repository then there is no need to provide credentials. If you don’t know how to create credentials for your private repository<strong> </strong>you can watch this <a href="https://www.youtube.com/watch?v=HSA_mZoADSw&amp;t=321s&amp;ab_channel=CloudBeesTV">video</a>.</p><p>You also need to change <strong>Branches to build</strong> to <strong>*/main </strong>this depends on your branch name for me branch name is the main.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xWGW0UgIRFn5JDzM" /></figure><p>As you are pulling your pipeline script from your repo itself you need to add the absolute of your Jenkins file inside <strong>Script Path</strong>. In my case, <strong>Jenkinsfile</strong> is under the Jenkins folder on my repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*k7-KHWnkrpeDw1mU" /></figure><p>Then click on <strong>Apply</strong> and <strong>Save</strong></p><p>For manual deployment, you can click <strong>Build Now</strong>. If GitHub is configured for auto-build then any changes inside the repo will automatically trigger the build</p><h4>Changing the jenkinsfile</h4><p>We will be modifying our Jenkins file as per our needs once you clone my <a href="https://github.com/parshuramgurav/serverless-framework-test">code</a> to your GitHub account.</p><p>Replace the CLOUDSDK_CORE_PROJECT value with your project ID and CLIENT_EMAIL_ID value with your service account Email ID which you created in the previous step.</p><pre>pipeline {<br>  agent any<br>  environment {<br>    CLOUDSDK_CORE_PROJECT=&#39;helpful-helper-364816&#39;<br>    CLIENT_EMAIL_ID=&#39;jenkins@helpful-helper-364816.iam.gserviceaccount.com&#39;<br>    GCLOUD_CREDS=credentials(&#39;gcloud-creds&#39;)<br>    GOOGLE_APPLICATION_CREDENTIALS=credentials(&#39;gcloud-creds&#39;)<br>  }<br>  stages {<br>    stage(&#39;version-testing&#39;) {<br>      steps {<br>        sh &#39;&#39;&#39;<br>          gcloud version<br>          gcloud auth activate-service-account --key-file=&quot;$GCLOUD_CREDS&quot;<br>          gcloud compute zones list<br>          whoami<br>          gcloud auth list<br>        &#39;&#39;&#39;<br>      }<br>    }<br>    stage(&#39;version check&#39;) {<br>      steps {<br>        sh &#39;&#39;&#39;<br>          node --version<br>          serverless --version<br>          serverless --help<br>          sudo npm install --save serverless-google-cloudfunctions<br>          serverless deploy<br>        &#39;&#39;&#39;<br>      }<br>    }<br>  }<br>  post {<br>    always {<br>      sh &#39;gcloud auth revoke $CLIENT_EMAIL_ID&#39;<br>    }<br>  }<br>}</pre><p>Now, you are ready to build and deploy your Serverless Framework. To start the build click on <strong>Build Now </strong>on the Jenkins console.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef91b97efe49" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>