Jenkins Single Stage Pipeline

Ticker

6/recent/ticker-posts

Jenkins Single Stage Pipeline

Question : The development team of xFusionCorp Industries is working on to develop a new static website and they are planning to deploy the same on Nautilus App Servers using Jenkins pipeline. They have shared their requirements with the DevOps team and accordingly we need to create a Jenkins pipeline job. Please find below more details about the task:

Click on the + button in the top left corner and select option Select port to view on Host 1, enter port 8081 and click on Display Port. You should be able to access the Jenkins login page. Login using username theadmin and Adm!n321 password.

In the same way you can access Gitea UI on port 8000; username and password for Git is sarah and Sarah_pass123 respectively. There under user sarah you will find a repository named web_app that is already cloned on Storage server under /home/sarah/web_app. sarah is a developer who is working on this repository.

Add a slave node named Storage Server. It should be labeled as ststor01 and its remote root directory should be /home/natasha.

We have already cloned repository on Storage Server under /home/sarah/web_app. Update the content of the file index.html under the same repository to Welcome to Nautilus Group! and push the changes to the origin into master branch.

Apache is already installed on all app Servers its running on port 6200.

Create a Jenkins pipeline job named datacenter-webapp-job (it must not be a Multibranch pipeline) and configure it to:

a. Deploy the code from web_app repository under /data on Storage Server, as this location is already mounted to the document root /var/www/html of app servers. The pipeline should have a single stage named Deploy ( which is case sensitive ) to accomplish the deployment.

Note:

You might need to install some plugins and restart Jenkins service. So, we recommend clicking on Restart Jenkins when installation is complete and no jobs are running on plugin installation/update page i.e update centre. Also, Jenkins UI sometimes gets stuck when Jenkins service restarts in the back end. In this case, please make sure to refresh the UI page.

For these kind of scenarios requiring changes to be done in a web UI, please take screenshots so that you can share it with us for review in case your task is marked incomplete. You may also consider using a screen recording software such as loom.com to record and share your work.

LB server is already configured. Click on the + button in the top left corner and select option Select port to view on Host 1, enter port 80 and click on Display Port. You should be able to see the latest changes you made. Please make sure the required content is loading on the main URL https://<LBR-URL> i.e there should not be a sub-directory like https://<LBR-URL>/web_app etc.

This task is based on web UI, you can refer below Video Solution for better understanding 


Solution: 

1. Click on the + button in the top left corner and select option Select port to view on Host 1, enter port 8081 and click on Display Port. You should be able to access the Jenkins login page. Login using username theadmin and Adm!n321 password.

2. Click Jenkins > Manage Jenkins > Manage Plugins and click Available tab.

Search for Pipeline Git, SSH Pipeline & SSH Build Agents  plugin and click Download now and install after restart





Refresh your browser  for the login screen


3. Before adding a new Slave Node as a prerequisite Java package need to be install 

thor@jump_host /$ ssh natasha@ststor01

The authenticity of host 'ststor01 (172.16.238.15)' can't be established.

ECDSA key fingerprint is SHA256:SySamszyWhhLGFiybhGBqfrr8g55wS/3e37ZpBOvICs.

ECDSA key fingerprint is MD5:6d:31:18:2a:f9:07:f3:29:dd:0a:d3:1f:6e:04:0a:db.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'ststor01,172.16.238.15' (ECDSA) to the list of known hosts.

natasha@ststor01's password:

[natasha@ststor01 ~]$ sudo su -

We trust you have received the usual lecture from the local System

Administrator. It usually boils down to these three things:

     #1) Respect the privacy of others.

    #2) Think before you type.

    #3) With great power comes great responsibility.

[sudo] password for natasha:

[root@ststor01 ~]#

[root@ststor01 ~]# rpm -qa |grep java

[root@ststor01 ~]#

[root@ststor01 ~]# yum install -y java

Loaded plugins: fastestmirror, ovl

Determining fastest mirrors

epel/x86_64/metalink                                                                                  |  29 kB  00:00:00    

 * base: centosmirror.netcup.net

 * epel: mirror.dogado.de

 * extras: mirror.checkdomain.de

 * updates: mirror.checkdomain.de

base                                                                                                  | 3.6 kB  00:00:00    

epel                                                                                                 

Installing:

 java-1.8.0-openjdk                      x86_64             1:1.8.0.292.b10-1.el7_9                updates             310 k

Installing for dependencies:

 alsa-lib                                x86_64             1.1.8-1.el7                            base                425 k

 atk                                     x86_64             2.28.1-2.el7                           base                263 k

 avahi-libs                              x86_64             0.6.31-20.el7                          base                 62 k

 cairo                                   x86_64             1.15.12-4.el7                          base                741 k

 copy-jdk-configs                        noarch             3.3-10.el7_5                           base                 21 k

 

[root@ststor01 ~]# rpm -qa |grep java

java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64

python-javapackages-3.4.1-11.el7.noarch

java-1.8.0-openjdk-headless-1.8.0.292.b10-1.el7_9.x86_64

javapackages-tools-3.4.1-11.el7.noarch

tzdata-java-2021a-1.el7.noarch

[root@ststor01 ~]#

4. Add a new slave node under Jenkins > Manage Jenkins > Manage Nodes and Clouds 






5. Wait for a few seconds for the agent to be configured.  Refresh the nodes list. 



6. Setup Credentials for GIT user sarah



7. Create a  new Pipeline Job


8. Kindly check the destination storage folder as per the task




//

// Setup up the Remote connection for SSH Build Pipeline step

//

def remote = [:]

remote.name = 'ststor01'

remote.host = 'ststor01'

remote.user = 'natasha'

remote.password = 'Bl@kW'

remote.allowAnyHosts = true   

            

pipeline {

    // Run on agent with label 'ststor01'

    agent { label 'ststor01' }

 

    // Pipeline stages

    stages {

        // Deploy stage 

        stage('Deploy') {

            steps {

                // Connect to GIT and download the repo code

                // Use the Jenkins Credentials by ID: GIT_CREDS

                git credentialsId: 'GIT_CREDS', url: 'http://git.stratos.xfusioncorp.com/sarah/web_app.git'

                // Transfer all the files we downloaded to /tmp of ststor01

                sshPut remote: remote, from: '.', into: '/tmp'

                // Finally move all the files from /tmp to /data on ststor01

                sshCommand remote: remote, command: "mv -f /tmp/${JOB_NAME}/* /data"

            }

        }

    }

}

 

9.  Login on Storage Server & Commit changes to index.html

thor@jump_host /$ ssh sarah@ststor01

The authenticity of host 'ststor01 (172.16.238.15)' can't be established.

ECDSA key fingerprint is SHA256:SySamszyWhhLGFiybhGBqfrr8g55wS/3e37ZpBOvICs.

ECDSA key fingerprint is MD5:6d:31:18:2a:f9:07:f3:29:dd:0a:d3:1f:6e:04:0a:db.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'ststor01,172.16.238.15' (ECDSA) to the list of known hosts.

sarah@ststor01's password:

[sarah@ststor01 ~]$

[sarah@ststor01 ~]$ cd /home/sarah/web_app/

[sarah@ststor01 web_app]$ ll

total 4

-rw-r--r-- 1 sarah sarah 35 Jun 22 09:33 index.html

[sarah@ststor01 web_app]$ cat index.html

Welcome to xFusionCorp Industries!

[sarah@ststor01 web_app]$

[sarah@ststor01 web_app]$ curl http://stapp01:6200

Welcome to xFusionCorp Industries!

[sarah@ststor01 web_app]$

[sarah@ststor01 web_app]$ vi index.html

[sarah@ststor01 web_app]$ cat index.html

Welcome to Nautilus Group!

[sarah@ststor01 web_app]$

[sarah@ststor01 web_app]$ git add index.html

[sarah@ststor01 web_app]$ git commit -m "update"

[master f8af1e4] update

 1 file changed, 1 insertion(+), 1 deletion(-)

[sarah@ststor01 ~]$

 [sarah@ststor01 web_app]$ git push origin master

Counting objects: 5, done.

Writing objects: 100% (3/3), 269 bytes | 0 bytes/s, done.

Total 3 (delta 0), reused 0 (delta 0)

remote: . Processing 1 references

remote: Processed 1 references in total

To http://sarah:Sarah_pass123@git.stratos.xfusioncorp.com/sarah/web_app.git

   091c946..f8af1e4  master -> master

[sarah@ststor01 web_app]$

10.  Validate the task by running build job in newly created Pipeline & Check console output




[sarah@ststor01 web_app]$ curl http://stapp01:6200

Welcome to Nautilus Group!

[sarah@ststor01 web_app]$ curl http://stapp02:6200

Welcome to Nautilus Group!

[sarah@ststor01 web_app]$ curl http://stapp03:6200

Welcome to Nautilus Group!

[sarah@ststor01 web_app]$

11. Click on Finish & Confirm to complete the task successfully

Happy Learning!!!!


Apart from this if you need more clarity,  I have made a  tutorial video on this , 

please go through and share your comments. Like and share the knowledge



Post a Comment

0 Comments

Latest Posts

KodeKloud Kubernetes Security CKS  Lab Challenge 4 |  Audit-policy | Install & configure falco utility | Inspect the API server audit logs and identify the user