Jenkins Assignment

·

3 min read

1] Set up web hook trigger for freestyle & pipeline projects

Free Style

Pipeline


2] Trigger jenkins parameterized freestyle job/ pipeline job using URL from a shell file


3] Generate artifact in any Agent and then deploy it to Tomcat server


4] Create two Jenkins pipelines in GitHub, that checkouts, test, builds and deploys the java application to a tomcat server.

 Using declarative pipeline with name Jenkinsfile.declarative

 Using scripted pipeline with name Jenkinsfile.groovy

  • Jenkinsfile.declarative

  • Jenkinsfile.groovy


5] Configure Jenkins to send email notification containing status of the job, it should include Job-name, Build no, job- URL. Configure your email address with Jenkins execute any pipeline job for this.


6] Setup multi-branch pipeline for a repository having four branches and build each branch whenever changes are found in a respective branch. Setup web-hook for this.


7] Write a pipeline having 4 stages with below configuration.

-> 2 agents, and run 2 stages in each.

-> Triggers (Periodic, Pol SCM)

-> Setup 3 environment variables, and use the pipeline steps.

-> Pass values dynamically for above 3 variables (String, Choice, Boolean)

-> Use any 4 Global variables inside the pipeline.

-> Conditionals, 3rd stage should run only after the 2nd stage success and 4th stage should run only after the 3rd stage success.

-> Also, the 3rd stage should run only when checkout branch is master, dev.

-> Fourth stage should trigger any freestyle Jenkins job. Use build manually in freestyle job.

-> Credentials – secret text, username and password.

-> Post actions to send mail.


8] Pick any 4 freestyle jobs and map them. Create a view. Add user in Jenkins and user should have access to these stream of jobs.(Use matching pattern while providing access)


9] Explore on RC(return code) in shell script. Execute a shell script and print different RC at different stages of shell script.

A return code, often referred to as an exit code or error code, is a numerical value returned by a software program or script to indicate the success or failure of its execution. In many programming languages and operating systems, a return code of 0 typically signifies successful completion, while non-zero values indicate various types of errors or exceptions.

Return codes are essential for automation and error handling in scripting and programming, allowing developers and users to understand the outcome of a program's execution programmatically.

#!/bin/bash

# Some commands or operations here

# Check the return code of the last command
if [ $? -eq 0 ]; then
    echo "Success"
else
    echo "Error"
fi