{"id":4611,"date":"2020-02-11T09:07:08","date_gmt":"2020-02-11T09:07:08","guid":{"rendered":"https:\/\/www.sparksupport.com\/blog\/?p=4611"},"modified":"2024-07-01T04:27:37","modified_gmt":"2024-07-01T04:27:37","slug":"ci-cd-pipeline-using-jenkins-and-gogs-tutorial","status":"publish","type":"post","link":"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/","title":{"rendered":"How to Make a CI\/CD Pipeline using Jenkins and Gogs"},"content":{"rendered":"\n<p>In this blog, we will explore how to create a robust CI\/CD pipeline using two popular open-source tools, Jenkins and Gogs, and discover how this integration can dramatically enhance productivity, ensure code quality, and swiftly deliver top-notch applications to end users. Get ready to unlock the full potential of your development process with the seamless synergy of Jenkins and Gogs!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is CI\/CD?<\/h2>\n\n\n\n<p>Nowadays, the concept of CI\/CD is everywhere. CI stands for continuous integration and the CD stands for Continuous Deployment. CI\/CD is the backbone of the DevOps environment. It helps organizations to speed up the release of small features in new software, and implement the feedback and changes quickly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Gogs<\/h3>\n\n\n\n<p>Gogs is a free and open-source Git service written in the Go language. painless self-hosted Git service. You can install and configure Gogs on your own servers. It supports all platforms including Linux, Mac, and Windows. For more about Gogs, check their official document <a href=\"https:\/\/gogs.io\/docs\">https:\/\/gogs.io\/docs<\/a><\/p>\r\n<p>\n\n\n\n<\/p>\r\n<h3 class=\"wp-block-heading\">Jenkins<\/h3>\r\n<p>\n\n\n\n<\/p>\r\n<p>Jenkins is a self-contained open-source automation platform that can be used to automate all kinds of software development, testing, distribution, or deployment tasks.<\/p>\r\n<p>\n\n\n\n<\/p>\r\n<h2 class=\"wp-block-heading\">Create CI\/CD Pipeline using Jenkins and Gogs<\/h2>\r\n<p>\n\n\n<p>In this blog, I will show you how to create a simple CI\/CD Pipeline using Jenkins and Gogs. In this scenario, we have hosted a <a href=\"https:\/\/sparksupport.com\/django-development\/\">django<\/a> application on the Linux server. As of now, we are doing the following process if any changes are needed for the application. The developer pulls the live code from the Gogs repository and pushes it back to the repo after modifying the code. Then the System Administrator will pull the latest code from the Gogs repo to the application server.<\/p>\n<p><\/p>\n\n\n<\/p>\r\n<p>&nbsp;<\/p>\r\n<p>\n\n\n\n<\/p>\r\n<p><strong>We can automate the above processes with the help of CI\/CD.1<\/strong>. Developer pushes\/merges code into a branch in the repo. <br \/><br \/><strong>2<\/strong>. Admin gets a notification message in Slack about the push <br \/><br \/><strong>3<\/strong>. Gogs trigger the Jenkins job for the new build and initiate the build if the conditions satisfy those specified in the Jenkins. <br \/><br \/><strong>4<\/strong>. Admin gets a notification message after the build. <br \/><br \/><strong>5<\/strong>. Once the build is completed, Jenkins will trigger the code deployment into the application server.<br \/><br \/><strong>6<\/strong>. Finally the application server will pull the latest code from the Gogs repo and send a notification message to Slack.\u00a0<\/p>\r\n<p>\n\n\n\n<\/p>\r\n<p>&nbsp;<\/p>\r\n<p>\n\n\n\n<\/p>\r\n<figure class=\"wp-block-image aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/0isk4IT7U2rI10hyJQxD8dWNGVLyGAWHIlhEAdA85UHAs1Cwb0Sc7QdjU50CwxwM0xZNcLLogcL-HzobcECiKmqL8I84TRXrCtD5cCY3Va7OkhfpY9dVipD8w7KDG2_48tHNPmAN\" alt=\"CI\/CD Pipeline using Jenkins and Gogs img 1\" width=\"514\" height=\"386\" \/><\/figure>\r\n<p>\n\n\n\n<\/p>\r\n<p>You may get a clear picture of this CI\/CD Pipeline using Jenkins and Gogs from the above diagram.<\/p>\r\n<p>\n\n\n\n<\/p>\r\n<h4 class=\"wp-block-heading\">Requirements\u00a0 \u00a0<\/h4>\r\n<p>\n\n\n\n<\/p>\r\n<ul class=\"wp-block-list\">\n\n<li>SSH access to Jenkins server.<\/li>\n\n\r\n\r\n\n<li>Gogs admin access.<\/li>\n\n\r\n\r\n\n<li>SSH access to the application server.<\/li>\n\n<\/ul>\r\n<p>\n\n\n\n<\/p>\r\n<h3 class=\"wp-block-heading\">1. Install plugins on Jenkins.<\/h3>\r\n<p>\n\n\n\n<\/p>\r\n<p><em>Required plugins: Git, Gogs<\/em><\/p>\r\n<ul>\r\n<li>Login to your Jenkins web interface.<\/li>\r\n<li>Go to Plugins Manage<\/li>\r\n<li>The search required plugins from there and click on \u201c Download now and install after restart\u201d<\/li>\r\n<\/ul>\r\n<p>\n\n\n\n<\/p>\r\n<figure class=\"wp-block-image aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/DGXOIspaOhrpZYPF45U3rpjrj_ZWiU31KbDENEOv2Iazwvh5Hp0e_j4Rds9QwR-ZaROI8EgO0AyM1QOSF6B-C1Koy7OY7NuYhZBoUGooOWbkGnxoci7k-ug_sW0Q7nt66ObeGLvR\" alt=\"CI\/CD Pipeline img2\" width=\"507\" height=\"342\" \/><\/figure>\r\n<p>\n\n\n\n<\/p>\r\n<div class=\"wp-block-image\">\r\n<figure><\/figure>\r\n<p>&nbsp;<\/p>\r\n<\/div>\r\n<p>\n\n\n\n<\/p>\r\n<h3 class=\"wp-block-heading\">2. Configure Webhook<\/h3>\r\n<p>\n\n\n\n\n\n<\/p>\r\n<figure class=\"wp-block-image aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/7SOYuInoFC5dSFA3LPmfyUS1sbkABYaZ0Fyb0so3mOpQydhuLaFf1gXmm1QQ58vMZr9bsVUAJ1ISuopaeIEIzZawVeKEH04oxhWu4GuEnydUR9_eacM6D7CNMBuH0xXWzW6w7G-Z\" alt=\"using Jenkins and Gogsimg4\" width=\"507\" height=\"342\" \/><\/figure>\r\n<p>\n\n\n\n<\/p>\r\n<h3 class=\"wp-block-heading\"><strong>3. Configure access to Gogs from Jenkins.<\/strong><\/h3>\r\n<p>\n\n\n\n<\/p>\r\n<p><strong>SSH<\/strong> <br \/><br \/>\u00a0 \u00a0 \u00a0 \u00a0 &gt;&gt; Login to your Jenkins server through ssh and generate a ssh key.<br \/><br \/><\/p>\r\n<p>\n\n\n\n<\/p>\r\n<div class=\"command\">\u00a0 \u00a0 \u00a0 # ssh-keygen<\/div>\r\n<p>\n\n\n\n<\/p>\r\n<p><br \/>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0&gt;&gt; The ssh private and public keys will be generated in \/var\/jenkins_home\/.ssh\/ Copy that public key from there. <br \/><br \/><\/p>\r\n<p>\n\n\n\n<\/p>\r\n<div class=\"command\">\u00a0 \u00a0 \u00a0 # cat \/var\/jenkins_home\/.ssh\/id_rsa.pub<\/div>\r\n<p>\n\n\n\n<\/p>\r\n<p><br \/>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &gt;&gt; Login to your Gogs and go to your Repository Settings &gt; Deploy keys Add previously copied public key here<\/p>\r\n<p>\n\n\n\n<\/p>\r\n<figure class=\"wp-block-image aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/5oTR-fuIvvnRj5siVO286V4WvZlmJBeUIIFmK6c8sSnOoORJmFQZ-tCALL1jDv0z02zQAFYtj14QmjPtmptA_QCfpr0uZHJkVZ7AUVyS2Ds_hmKG252INJsSrKJaunVm8u40xEfc\" alt=\" using Jenkins and mg 5\" width=\"507\" height=\"342\" \/><\/figure>\r\n<p>\n\n\n\n<\/p>\r\n<blockquote>\r\n<p>&gt;&gt; Add this private key in Jenkins credentials. <br \/><br \/>&gt;&gt; Login to your Jenkins server and go to: <br \/><br \/>&gt;&gt; Jenkins &gt; Credentials &gt; System &gt; Global credentials <br \/><br \/>&gt;&gt; Then select \u201cSSH username with private key\u201d from the Drop down menu.<\/p>\r\n<\/blockquote>\r\n<p>\n\n\n\n<\/p>\r\n<blockquote>\r\n<p><span style=\"font-size: revert; color: initial;\">&gt;&gt; Enter the Gogs ssh username and paste the previously created private key there.<\/span><\/p>\r\n<\/blockquote>\r\n<p>\n\n\n\n<\/p>\r\n<figure class=\"wp-block-image aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/Vsyh2JjSxJXyq03jjbpZqxwEDDMN6-Uzt3ZjxJF0Iztc36_0uSLtAxwJ4ezvSqm3HzJgd0-M0c4CdeRxVfLROR59ehu1bQcpwTBJtci84dGpvB4Xw9P_Wr_zpyWe9MJscnm4kqfo\" alt=\"Jenkins and Gogs img6\" width=\"507\" height=\"342\" \/><\/figure>\r\n<p>\n\n\n\n<\/p>\r\n<p><strong>Username and password<\/strong><\/p>\r\n<p>\n\n\n\n<\/p>\r\n<ul class=\"wp-block-list\">\n\n<li>You can also configure this with your Gogs username and password.<\/li>\n\n\r\n\r\n\n<li>Go to Jenkins &gt;&gt; Credentials &gt;&gt; System &gt;&gt; Global credentials<\/li>\n\n\r\n\r\n\n<li>Enter your Gogs user username and password there.<\/li>\n\n<\/ul>\r\n<p>\n\n\n\n<\/p>\r\n<figure class=\"wp-block-image aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/QNyGOAVWQe9eXRn31ymoml_5-H6p-lqGJZ794sRq7FaSc0TtosRL0a0JG9QBpVYxCEt5rQyiDVLMRsfJkOj3i2G3oEZ8csgUZAyxaIeaOZb6jepfs_YDZrVidw66FPbTLbKkgHM_\" alt=\"CI\/CD Pipeline using\" width=\"507\" height=\"342\" \/><\/figure>\r\n<p>\n\n\n\n<\/p>\r\n<h3 class=\"wp-block-heading\"><strong>4. Configure SSH access to the application server from Jenkins.<\/strong><\/h3>\r\n<p>\n\n\n\n<\/p>\r\n<p>In this example, I have a user called Jenkins in the application server.<\/p>\r\n<p>\n\n\n\n<\/p>\r\n<ul class=\"wp-block-list\">\n\n<li>Login to your Jenkins server through SSH.<\/li>\n\n\r\n\r\n\n<li>Copy the previously created key to the application server <br \/># ssh-copy-id jenkins@192.168.1.35<\/li>\n\n\r\n\r\n\n<li>Now configure these ssh details in Jenkins.<\/li>\n\n\r\n\r\n\n<li>Install the \u201cPublish over SSH\u201d plugin<\/li>\n\n\r\n\r\n\n<li>Go to Jenkins &gt; Manage Jenkins &gt; Configure System &gt; Publish Over SSH<br \/><br \/><br \/><br \/><\/li>\n\n<\/ul>\r\n<p>\n\n\n\n<\/p>\r\n<figure class=\"wp-block-image aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/NeetobhJM5G-C63UPukCb46PeVW8nqSvbPr3fSWTpKSv0ZB8-aO32PJV0i8AUUt6mGiG0nsCx3dHxpqN5vkz4CDDb7hwaLxeHcfUnf-U7n1-TDlDbkpis429zXk1nHUv1O4S5138\" alt=\"Jenkins and img9\" width=\"507\" height=\"342\" \/><\/figure>\r\n<p>\n\n\n\n<\/p>\r\n<p>If you get any error as shown in the below screenshot, create the ssh key with the following options in the 3rd step.<br \/># ssh-keygen -t rsa -b 4096 -m PEM<\/p>\r\n<p>\n\n\n\n<\/p>\r\n<figure class=\"wp-block-image aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/MyWG1MnnwAYhcHCOfbjNrpoKVib8qy7yCUxM5UJ4KlgFzt1P4V-ITsrLQDIBdKvKePiSHxAuB4sr9WoVWwNe5JZMIXLlg37O52SgKdE3HYPs4wSQIpRmFU--Et9BBZtoCY3YXeSx\" alt=\"Pipeline using img10\" width=\"507\" height=\"342\" \/><\/figure>\r\n<p>\n\n\n\n<\/p>\r\n<h3 class=\"wp-block-heading\">5. Configure Jenkins job<\/h3>\r\n<p>\n\n\n\n<\/p>\r\n<ul>\r\n<li>Login to your Jenkins dashboard.<\/li>\r\n<li>Go to Jenkins &gt; New Item.<\/li>\r\n<li>Enter your project name and select \u201cFreestyle project\u201d<\/li>\r\n<\/ul>\r\n<p>\n\n\n\n<\/p>\r\n<figure class=\"wp-block-image aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/y6WxpgaBy5LG9RmsydCovfDolDp9RMIaM1U2ju6xJyUoQpLGBR48d3jRZZZH4nlMc8HIcctUq_3Y8ylUa0QR-ZHvYHQ8-y5Ea5zDXBuKPzZn_pPbqu_mmxElzAGS-IKSb_aO7bK1\" alt=\" Jenkins and Gogs img11\" width=\"507\" height=\"342\" \/><\/figure>\r\n<p>\n\n\n\n<\/p>\r\n<p>In this job, we are executing a bash script to deploy the code into the application server. So we need string parameters to pass into the bash script as an argument.<\/p>\r\n<ul>\r\n<li>So select the option \u201cThis project is parameterized\u201d under Gogs webhook<\/li>\r\n<li>Then add the parameter \u201c GIT_FOLDER\u201d<\/li>\r\n<li>Specify the directory name in the application server to which the git pull happens for code deployment.<\/li>\r\n<li>In my case, the directory is \/home\/jenkins\/cd-dev<\/li>\r\n<\/ul>\r\n<p>\n\n\n\n<\/p>\r\n<figure class=\"wp-block-image aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/lsPv5OhueSrR4PfYggYJLIlF5WvIGMtnuU3V5P3zUnnGNGl6i4Ze6Bv6j0La2jrj0t7EN0NV4EFGcf3DCe5N_vZR6Rnv0aGSUadvPplm0y54GeLJ3GphSwM6oZeUCrxZJuQOuzKB\" alt=\" Pipeline   img12\" width=\"507\" height=\"342\" \/><\/figure>\r\n<p>\n\n\n\n<\/p>\r\n<div class=\"wp-block-image\">\u00a0<\/div>\r\n<p>\n\n\n\n<\/p>\r\n<ul>\r\n<li>Add next parameter is \u201cGIT_CHECKOUT_DIR\u201d<\/li>\r\n<\/ul>\r\n<p>\n\n\n\n<\/p>\r\n<ul>\r\n<li>Specify the directory name in the application server to which will deploy the code.<\/li>\r\n<\/ul>\r\n<p>\n\n\n\n<\/p>\r\n<figure class=\"wp-block-image aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/yq8HlbCYx9CB0OBb8QBGbYPBeXTRz9bZVl6Tlv6NyN5yXNfTWXgZ43EaQMvB9AI02r60YJU8xfvKHEVRVm0-lYzHaihzHqkqIpXdGxcrD8o9Q4LY5Li5kDk3xGhni8QdAp3NsEJ0\" alt=\"CI\/CD  img13\" width=\"507\" height=\"342\" \/><\/figure>\r\n<p>\n\n\n\n<\/p>\r\n<div class=\"wp-block-image\">\u00a0<\/div>\r\n<p>\n\n\n\n<\/p>\r\n<ul>\r\n<li>Next parameter is \u201cSERVER_ENV\u201d<\/li>\r\n<\/ul>\r\n<p>\n\n\n\n<\/p>\r\n<figure class=\"wp-block-image aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/3-R_XG7l6MkX_74UcOU-YsFhm8hgpjQGoY9Z5TAqwuOCevKCi1Ca0GcSjmYhUl8U9uM6z6sie3AFmDxm2GsoNMwesLK7E7l4RPFDnNnTCkKaI4gcsnwzNeZ6Goe4KUvOs_OK5SSU\" alt=\"CI\/ img14\" width=\"507\" height=\"342\" \/><\/figure>\r\n<p>\n\n\n\n<\/p>\r\n<ul>\r\n<li>The next parameter is \u201cVENV\u201d<\/li>\r\n<\/ul>\r\n<p>\n\n\n\n<\/p>\r\n<ul>\r\n<li>Specify your Python virtual environment path in the application server.<\/li>\r\n<\/ul>\r\n<p>\n\n\n\n<\/p>\r\n<figure class=\"wp-block-image aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/sBgSpbMsw9CT6ykhIAiXS5806CZgL988imrrrqZ2Z18Z3bfyAX9lxraqsj7gVxI7XMz6pUpRnJNUkZT0LZYYajxvrkqf5mU41HEzS_id-TFsGQe2LfjzrC25PnW0QikgL-L-qyTz\" alt=\"CI\/CD Pipeline img15\" width=\"507\" height=\"342\" \/><\/figure>\r\n<p>\n\n\n\n<\/p>\r\n<div class=\"wp-block-image\">\u00a0<\/div>\r\n<p>\n\n\n\n<\/p>\r\n<ul>\r\n<li>Then add the parameter \u201cDEPLOY_SCRIPT\u201d<\/li>\r\n<li>This variable stores the path of the deploy script<\/li>\r\n<\/ul>\r\n<p>\n\n\n\n<\/p>\r\n<figure class=\"wp-block-image aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/KJ6krPDhO4X82RRL9aii_F8OO-7TMF3YTV5U6iOtktzW2yDQMK7Ifotl9IGaY0NWOjkA-Hjzi1xz1JXORvMkLRScuNGmgg6FlcF9epvPOQEZYPJflCNjTfTtAQ0ixf_0du6oyAZO\" alt=\"CI\/CD  using  and Gogs img16\" width=\"507\" height=\"342\" \/><\/figure>\r\n<p>\n\n\n\n<\/p>\r\n<div class=\"wp-block-image\">\u00a0<\/div>\r\n<p>\n\n\n\n<\/p>\r\n<p>I will show you the content of the script at the end of the tutorial.<\/p>\r\n<ul>\r\n<li>Now add the Gogs repo URL and credentials in the \u201cSource Code Management\u201d and you can select previously added credentials from there.<\/li>\r\n<\/ul>\r\n<p>\n\n\n\n<\/p>\r\n<figure class=\"wp-block-image aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/i2EboB6In9H44rPTCU9BCsOfr7L2fehXWTf_fXQ64cJMzK5E1UGVcspz87Bfgu9CFaMiQixscsRadDAex92pgB6dxfSZj7jrjYEuoxaAnA5PfKiVD7FYOXQnuSSbynhNMjXErGqg\" alt=\"CI\/CD Pipeline  Jenkins and  img17\" width=\"507\" height=\"342\" \/><\/figure>\r\n<p>\n\n\n\n<\/p>\r\n<div class=\"wp-block-image\">\u00a0<\/div>\r\n<p>\n\n\n\n<\/p>\r\n<ul class=\"wp-block-list\">\n\n<li>Finally, go to the \u201cPost-build Action\u201d in the Jenkins job.<\/li>\n\n\r\n\r\n\n<li>Select \u201cSend build Artifacts over SSH\u201d and paste the following command in the \u201cExec command box\u201d<\/li>\n\n<\/ul>\r\n<p>\n\n\n\n<\/p>\r\n<p>cd $GIT_FOLDER &amp;&amp; git fetch &amp;&amp; if ! (git diff &#8211;exit-code &#8211;name-only $GIT_BRANCH &#8212; $DEPLOY_SCRIPT); then git pull;fi &amp;&amp; bash $DEPLOY_SCRIPT\u00a0 $GIT_FOLDER $GIT_BRANCH $GIT_CHECKOUT_DIR $GIT_URL $SERVER_ENV $VENV<\/p>\r\n<p>\n\n\n\n<\/p>\r\n<figure class=\"wp-block-image aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/vpPN3Zy9u18E7jGs4lFCEEvcpoAai1YBi8BdlD1w1bux6pTt88NfMbhFmK4JqlAeehrASRDdVTvu9WzG0edGdnVGp7BrWDpF8EkPHklySaMOVhDWBMD9g7e4PY1kXy3vVBT0PN5M\" alt=\"CI\/CD Pipeline Gogs img18\" width=\"507\" height=\"342\" \/><\/figure>\r\n<p>\n\n\n\n<\/p>\r\n<div class=\"wp-block-image\">\u00a0<\/div>\r\n<p>\n\n\n\n<\/p>\r\n<p>If the conditions satisfy, Jenkins will pull files from the gogs repo and execute the deploy script with the above-mentioned arguments.<\/p>\r\n<p>\n\n\n\n<\/p>\r\n<p><br \/>Here is the deploy script written in the bash script.<\/p>\r\n<p>\n\n\n\n<\/p>\r\n<figure class=\"wp-block-table is-style-stripes\">\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td>###Beginning##<br \/>#!\/bin\/bash<br \/>#Deployment script used by Jenkins<br \/>#Author: Hans Emmanuel<br \/>GIT_FOLDER=$1<br \/>GIT_BRANCH=$2<br \/>GIT_CHECKOUT_DIR=$3<br \/>GIT_URL=$4<br \/>SERVER_ENV=$5<br \/>VENV=$6<br \/>PIP_INS=false<br \/>DEPLOYED=false<br \/>SLACK_URL= \u00a0&lt;specify your slak url if you are using slack&gt;<br \/><br \/><br \/>cd $GIT_FOLDER<br \/>git fetch<br \/>if (git cat-file -e $GIT_BRANCH:DEPLOY)<br \/>then<br \/>echo &#8220;deploying the code&#8221;<br \/>BRANCH=$(echo ${GIT_BRANCH} | cut -d&#8217;\/&#8217; -f2)<br \/>\u00a0if ! (git diff &#8211;exit-code &#8211;name-only $GIT_BRANCH &#8212; requirements.txt)<br \/><br \/><br \/>then<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PIP_INS=true<br \/><br \/>fi<br \/>git pull &amp;&amp; GIT_WORK_TREE=$GIT_CHECKOUT_DIR git checkout $BRANCH\u00a0 -f &amp;&amp; DEPLOYED=true &amp;&amp; echo &#8220;CODE Deployed&#8221;<br \/><br \/><br \/>\u00a0cd $GIT_CHECKOUT_DIR<br \/>\u00a0\u00a0\u00a0\u00a0 if $PIP_INS<br \/>then<br \/>cd $GIT_CHECKOUT_DIR<br \/>echo &#8220;Installing requirements&#8221;<br \/>source $VENV\/bin\/activate<br \/>pip install -r requirements.txt<br \/><br \/><br \/>fi<br \/>touch $GIT_CHECKOUT_DIR\/uwsgi.ini<br \/>url=$GIT_URL<br \/>REPO=$(basename $url)<br \/>if $DEPLOYED<br \/>then<br \/>curl -X POST &#8211;data &#8220;payload={\\&#8221;text\\&#8221;: \\&#8221;:slack: Jenkins Repo <em>$REPO<\/em> branch <em>${GIT_BRANCH}<\/em> Deployment is <em>SUCCESS<\/em> on <em>${SERVER_ENV}<\/em> server\\&#8221;}&#8221; $SLACK_URL<br \/><br \/><br \/>else<br \/>curl -X POST &#8211;data &#8220;payload={\\&#8221;text\\&#8221;: \\&#8221;:slack:\u00a0 Jenkins Repo *$REPO* branch *${GIT_BRANCH}* Deployment is *FAILED* on *${SERVER_ENV}* server\\&#8221;}&#8221; $SLACK_URL<br \/><br \/>fi<br \/>else echo &#8220;NOT Deploying Code&#8221;<br \/>fi<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n<p>\n\n\n\n<\/p>\r\n<p class=\"custom_code has-black-color has-text-color\">Check the Articles<\/p>\r\n<p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><a href=\"https:\/\/sites.google.com\/sparksupport.com\/hire-php-developers\/home\">6 Best Cost-Effective Companies to Hire PHP Developers<\/a><\/strong><\/li>\n<\/ul>\n\n\n\n<\/p>\r\n<p>&nbsp;<\/p>\r\n<p>\n\n\n\n<\/p>\r\n<p>&nbsp;<\/p>\r\n<p>\n\n\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>In this blog, we will explore how to create a robust CI\/CD pipeline using two popular open-source tools, Jenkins and Gogs, and discover how this<\/p>\n","protected":false},"author":1,"featured_media":4763,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[246],"tags":[244,245],"class_list":["post-4611","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ci-cd","tag-ci-cd-pipeline","tag-cicd-pipeline-using-jenkins"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Make a CI\/CD Pipeline using Jenkins and Gogs<\/title>\n<meta name=\"description\" content=\"In this blog, we will provide a comprehensive overview and detailed, step-by-step tutorial on how to build a CI\/CD pipeline using Jenkins.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Make a CI\/CD Pipeline using Jenkins and Gogs\" \/>\n<meta property=\"og:description\" content=\"In this blog, we will provide a comprehensive overview and detailed, step-by-step tutorial on how to build a CI\/CD pipeline using Jenkins.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-02-11T09:07:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-01T04:27:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2020\/02\/How-to-Make-a-CICD-Pipeline-Using-Jenkins-and-Gogs-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1256\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"SparkSupport\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"SparkSupport\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/\"},\"author\":{\"name\":\"SparkSupport\",\"@id\":\"https:\/\/sparksupport.com\/blog\/#\/schema\/person\/b359b1e8bc00b1d71637775f13a9ec44\"},\"headline\":\"How to Make a CI\/CD Pipeline using Jenkins and Gogs\",\"datePublished\":\"2020-02-11T09:07:08+00:00\",\"dateModified\":\"2024-07-01T04:27:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/\"},\"wordCount\":1199,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2020\/02\/How-to-Make-a-CICD-Pipeline-Using-Jenkins-and-Gogs-1.png\",\"keywords\":[\"ci cd pipeline\",\"cicd pipeline using jenkins\"],\"articleSection\":[\"CI CD\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/\",\"url\":\"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/\",\"name\":\"How to Make a CI\/CD Pipeline using Jenkins and Gogs\",\"isPartOf\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2020\/02\/How-to-Make-a-CICD-Pipeline-Using-Jenkins-and-Gogs-1.png\",\"datePublished\":\"2020-02-11T09:07:08+00:00\",\"dateModified\":\"2024-07-01T04:27:37+00:00\",\"description\":\"In this blog, we will provide a comprehensive overview and detailed, step-by-step tutorial on how to build a CI\/CD pipeline using Jenkins.\",\"breadcrumb\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/#primaryimage\",\"url\":\"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2020\/02\/How-to-Make-a-CICD-Pipeline-Using-Jenkins-and-Gogs-1.png\",\"contentUrl\":\"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2020\/02\/How-to-Make-a-CICD-Pipeline-Using-Jenkins-and-Gogs-1.png\",\"width\":2400,\"height\":1256,\"caption\":\"How to Make a CICD Pipeline Using Jenkins and Gogs\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/sparksupport.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Make a CI\/CD Pipeline using Jenkins and Gogs\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/sparksupport.com\/blog\/#website\",\"url\":\"https:\/\/sparksupport.com\/blog\/\",\"name\":\"SparkSupport Blog\",\"description\":\"SparkSupport Blogs\",\"publisher\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/sparksupport.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/sparksupport.com\/blog\/#organization\",\"name\":\"SparkSupport\",\"url\":\"https:\/\/sparksupport.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/sparksupport.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2019\/08\/cropped-logo-1.jpg\",\"contentUrl\":\"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2019\/08\/cropped-logo-1.jpg\",\"width\":216,\"height\":44,\"caption\":\"SparkSupport\"},\"image\":{\"@id\":\"https:\/\/sparksupport.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/sparksupport.com\/blog\/#\/schema\/person\/b359b1e8bc00b1d71637775f13a9ec44\",\"name\":\"SparkSupport\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/4d86cc3c0d188e40e99abec16795ed658b95c89ab15427bd7254315e8115b40b?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4d86cc3c0d188e40e99abec16795ed658b95c89ab15427bd7254315e8115b40b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4d86cc3c0d188e40e99abec16795ed658b95c89ab15427bd7254315e8115b40b?s=96&d=mm&r=g\",\"caption\":\"SparkSupport\"},\"url\":\"https:\/\/sparksupport.com\/blog\/author\/spark_wp_admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Make a CI\/CD Pipeline using Jenkins and Gogs","description":"In this blog, we will provide a comprehensive overview and detailed, step-by-step tutorial on how to build a CI\/CD pipeline using Jenkins.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"How to Make a CI\/CD Pipeline using Jenkins and Gogs","og_description":"In this blog, we will provide a comprehensive overview and detailed, step-by-step tutorial on how to build a CI\/CD pipeline using Jenkins.","og_url":"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/","article_published_time":"2020-02-11T09:07:08+00:00","article_modified_time":"2024-07-01T04:27:37+00:00","og_image":[{"width":2400,"height":1256,"url":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2020\/02\/How-to-Make-a-CICD-Pipeline-Using-Jenkins-and-Gogs-1.png","type":"image\/png"}],"author":"SparkSupport","twitter_card":"summary_large_image","twitter_misc":{"Written by":"SparkSupport","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/#article","isPartOf":{"@id":"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/"},"author":{"name":"SparkSupport","@id":"https:\/\/sparksupport.com\/blog\/#\/schema\/person\/b359b1e8bc00b1d71637775f13a9ec44"},"headline":"How to Make a CI\/CD Pipeline using Jenkins and Gogs","datePublished":"2020-02-11T09:07:08+00:00","dateModified":"2024-07-01T04:27:37+00:00","mainEntityOfPage":{"@id":"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/"},"wordCount":1199,"commentCount":0,"publisher":{"@id":"https:\/\/sparksupport.com\/blog\/#organization"},"image":{"@id":"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2020\/02\/How-to-Make-a-CICD-Pipeline-Using-Jenkins-and-Gogs-1.png","keywords":["ci cd pipeline","cicd pipeline using jenkins"],"articleSection":["CI CD"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/","url":"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/","name":"How to Make a CI\/CD Pipeline using Jenkins and Gogs","isPartOf":{"@id":"https:\/\/sparksupport.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2020\/02\/How-to-Make-a-CICD-Pipeline-Using-Jenkins-and-Gogs-1.png","datePublished":"2020-02-11T09:07:08+00:00","dateModified":"2024-07-01T04:27:37+00:00","description":"In this blog, we will provide a comprehensive overview and detailed, step-by-step tutorial on how to build a CI\/CD pipeline using Jenkins.","breadcrumb":{"@id":"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/#primaryimage","url":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2020\/02\/How-to-Make-a-CICD-Pipeline-Using-Jenkins-and-Gogs-1.png","contentUrl":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2020\/02\/How-to-Make-a-CICD-Pipeline-Using-Jenkins-and-Gogs-1.png","width":2400,"height":1256,"caption":"How to Make a CICD Pipeline Using Jenkins and Gogs"},{"@type":"BreadcrumbList","@id":"https:\/\/sparksupport.com\/blog\/ci-cd-pipeline-using-jenkins-and-gogs-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/sparksupport.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Make a CI\/CD Pipeline using Jenkins and Gogs"}]},{"@type":"WebSite","@id":"https:\/\/sparksupport.com\/blog\/#website","url":"https:\/\/sparksupport.com\/blog\/","name":"SparkSupport Blog","description":"SparkSupport Blogs","publisher":{"@id":"https:\/\/sparksupport.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/sparksupport.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/sparksupport.com\/blog\/#organization","name":"SparkSupport","url":"https:\/\/sparksupport.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/sparksupport.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2019\/08\/cropped-logo-1.jpg","contentUrl":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2019\/08\/cropped-logo-1.jpg","width":216,"height":44,"caption":"SparkSupport"},"image":{"@id":"https:\/\/sparksupport.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/sparksupport.com\/blog\/#\/schema\/person\/b359b1e8bc00b1d71637775f13a9ec44","name":"SparkSupport","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4d86cc3c0d188e40e99abec16795ed658b95c89ab15427bd7254315e8115b40b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4d86cc3c0d188e40e99abec16795ed658b95c89ab15427bd7254315e8115b40b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d86cc3c0d188e40e99abec16795ed658b95c89ab15427bd7254315e8115b40b?s=96&d=mm&r=g","caption":"SparkSupport"},"url":"https:\/\/sparksupport.com\/blog\/author\/spark_wp_admin\/"}]}},"_links":{"self":[{"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/posts\/4611","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/comments?post=4611"}],"version-history":[{"count":0,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/posts\/4611\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/media\/4763"}],"wp:attachment":[{"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/media?parent=4611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/categories?post=4611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/tags?post=4611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}