Jenkins Workspaces

Ticker

6/recent/ticker-posts

Jenkins Workspaces

  Question : Some developers are working on a common repository where they are testing some features for an application. They are having three branches (excluding the master branch) in this repository where they are adding changes related to these different features. They want to test these changes on Stratos DC app servers so they need a Jenkins job using which they can deploy these different branches as per requirements. Configure a Jenkins job accordingly.

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.

Click on the + button in the top left corner and select option Select port to view on Host 1, enter port 8000 and click on Display Port. You should be able to access the Gitea page. Login to Gitea server using username sarah and password Sarah_pass123.

There is a Git repository web_app on Gitea where developers are pushing their changes. It has three branches version1, version2 and version3 (excluding the master branch). You need not to make any changes in the repository.

Create a Jenkins job named as app-job.

Configure this job to have a choice parameter named Branch with choices as mentioned below:

version1

version2

version3

Configure the job to fetch changes from above mentioned Git repository and make sure it should fetch changes from the respective branch which you are passing as a choice in the choice parameter while building the job. For example if you choose version1 then it must fetch and deploy branch as version1.

Configured this job to use custom workspace rather than default workspace and custom workspace directory should be created under /var/jenkins_home/ (for example /var/jenkins_home/version1) location rather than under any sub-directory etc. The job should use a workspace as per the value you will pass for Branch parameter while building the job. For example if you choose version1 while building the job then it should create a workspace directory called version1 and should fetch Git repository etc within that directory only.

Configure the job to deploy code (fetched from Git repository) on storage server (in Stratos DC) under /data directory. Since its mounted as a NFS share on all app servers so eventually you should be able to see your changes on LBR URL.

You can access the website on LBR link. To do so click on the + button on top of your terminal, select option Select port to view on Host 1 and after adding port 80 click on Display Port.

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.

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 Git. Select Gitea, SSH & Publish over SSH plugin and click Download now and install after restart



3. In the following screen, click checkbox Restart Jenkins when installation is complete.


4. Setup Credentials for GIT user ( Sarah)

Jenkins > Manage Jenkins > Manage Credentials, click Global under Stores scoped to Jenkins and Add Credentials



5. Configure Publish Over SSH

Jenkins > Manage Jenkins > Configure System under Publish over SSH > SSH Servers click Add



6.  Login on storage server & Verify Permissions for /data directory

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 ~]#chmod 777 /data

[root@ststor01 ~]# ll  -lsd /data/

4 drwxrwxrwx 2 root root 4096 Jan 6 2020  /data

[root@ststor01 ~]#


7. Create a Parameterized Build



8. Copy GIT Repo URL

Select port to view on Host 1 and connect to port 8000. Login using the GITEA user and password given in the task

http://git.stratos.xfusioncorp.com/sarah/web.git


9. Configure Custom Workspace based on Choice Parameter

10.  Configure GIT Branch based on Choice Parameter & Set the Branches to Build to the value i.e. */$Branch





11. Under Build Environment , Configure SSH transfer to Storage server 


12. Click on Finish & Confirm to complete the task successful

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

1 Comments