Jenkins Assignment

·

3 min read

1] Create two Jenkins pipeline in github that checkouts, test, build and deploys the java application to a tomcat server

  • Using declarative pipeline with name jenkinsfile.declarative

  • using scripted pipeline with name jenkinsfile.groovy

  • Add the "Deploy to container" Plugin

    • jenkins declarative pipeline code

  • Jenkinsfile.groovy file code


2] Set up a freestyle jenkins job that builds java-app whenever changes are pushed to a git repository. Use webhook trigger

  • While configuring the project, in Build Triggers, u should choose GitHub hook trigger for GITScm polling

  • In the settings of the github repo, go to webhook & copy paste the url of the jenkins server:- http://<url>:8080/github-webhook/

  • & whenever a commit happens in SCM, it will hit the url which we have saved in the webhook section and the build will happen automatically


3] Configure jenkins to send email notifications informing status of the job. It should include Jobname, Build no, Job url. It should be done in both Freestyle and Pipeline jobs

  • go to Manage Jenkins -> System, & make the necessary email related configurations


4] Setup multi-branch pipeline for a repo having 4 branches & build each branch whenever changes are found in a respective branch. Setup webhook for this

  • Create a job using multibranch pipeline.

  • Add the Branch Sources → Git → Project Repository and save.

  • To use the webhook in Multibranch Pipeline we need to install Multibranch Scan Webhook Trigger in Manage Jenkins → Plugins.

  • Add webhook to our repo on GitHub

  • Add webhook token to Jenkins in Scan Multibranch Pipeline Triggers → Scan by webhook → Trigger token

  • make some changes in a branch

  • & it will trigger the build


5] Write a pipeline having 4 stages with below configs

  • 2 agents & run 2 stages in each

  • Triggers (periodic, pollscm)

  • Setup 3 env var & use in pipeline steps

  • pass values dynamically for above 3 var (string,choice,boolean)

  • use any 4 global var inside pipeline

  • Conditionals, 3rd stage should run only after 2nd stage success & 4th stage should run only after 3rd stage successs

  • also 3rd stage should run only when checkout branch is master, dev

  • Credentials-- secret text, username & password

  • Post actions to send mail


6] create 2 global roles, 2 item roles. Assign each item role to any 2 jobs. As well asign each global role to one user

  • Install Role-based Authorization Strategy Plugin

    Manage Jenkins -> Plugins -> Available Plugins -> Role-based Authorization Strategy -> install

  • Once we install the plugin, then Select Role Based Strategy under authorisation Manage Jenkins -> Security -> Authorization -> Select Role Based Strategy -> Save

  • Once we select Role Based Strategy we get the new option available in manage Jenkins named “Manage and Assign Roles”

  • Create users under Manage Jenkins -> Users -> Create User

  • ) Create 02 Global roles, 02 new roles

    Manage Jenkins -> Manage and Assign Roles -> Global Roles

  • Assign Global Roles to one user

    Manage Jenkins -> Manage and Assign Roles -> Assign Roles

  • Assigning each item role to any 2 jobs

    Manage Jenkins -> Manage and assig Roles -> Manage Roles -> Item Roles (create item Roles)

  • To Assign item Roles – Manage Jenkins -> Manage and Assign Roles -> Assign Roles