#Task_6 Devops JENKINS AND GROOVY
Task DESCRIPTION…
- Create container image that’s has Jenkins installed using dockerfile Or You can use the Jenkins Server on RHEL 8/7
2. When we launch this image, it should automatically starts Jenkins service in the container.
3. Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins
4. Job2 ( Seed Job ) : Pull the Github repo automatically when some developers push repo to Github.
5. Further on jobs should be pipeline using written code using Groovy language by the developer
6. Job1 :
1. By looking at the code or program file, Jenkins should automatically start the respective language interpreter installed image container to deploy code on top of Kubernetes ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed )
2. Expose your pod so that testing team could perform the testing on the pod
3. Make the data to remain persistent using PVC ( If server collects some data like logs, other user information )
7. Job3 : Test your app if it is working or not.
8. Job4 : if app is not working , then send email to developer with error messages and redeploy the application after code is being edited by the developer
STEP1: -
First we need to create a Seperate workspace for Task 6

now we need to create a docker file

STEP 2 :-
Now when we launch the image it will start jenkins automatically set the password and install the required plugins.
STEP 3:-
CREATE A SEED JOB
Now we will create the job which will download the code from the github into jenkins workspace automatically as the developer pushes to github.



then now ,Create the following yml files to deploy the webserver , persistent storage(PVC), exposing the service.
apiVersion: v1
kind: Service
metadata:
name: web-service
labels:
app: httpd
spec:
ports:
- nodePort: 9091
port: 80
targetPort: 80
selector:
app: httpd
tier: web
type: NodePort
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: volumeclaim
lables:
app: httpd
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpd
labels:
app: httpd
spec:
selector:
matchLables:
app: httpd
tier: web
strategy:
type: Recreate
template:
metadata:
labels:
app: httpd
tier: web
spec:
containers:
- image: rish27/httpd:v1
name: httpd
ports:
- containerPort: 80
name: httpd
volumeMounts:
- name: ps
mountPath: /var/www/html
volumes:
- name: ps
persistenVolumeClaim:
claimName: volumeclaim
now create the groovy transcript as
def gitUrl = 'git://github.com/test/test'
job('test-job') {
scm {
git(gitUrl)
}
triggers {
scm('*/15 * * * *')
}
steps {
maven('-e clean test')
}
}
If we pass the above script to the DSL seed job, it will dynamically generate a Jenkins job named “test-job”. If you submit an updated DSL, it will run the seed job and update “test-job” but not delete any history/builds.


Lastly Now to run the groovy script add this in the seed job in build option.


You now have the means to source control your Jenkins job configurations, and generate your jobs using the power and flexibility of Groovy in the Job DSL plugin. Even if the Job DSL doesn’t support a Jenkins plugin you’re using, you can still configure it without having to modify the Job DSL itself.
This workflow is great for us as it allows our developers full control over their Jenkins job and gives them quick feedback if there are any issues.
THANK YOU!!!
This project is made by Rishabh jain and Priyanshu goyal under the guidance of Mr Vimal Daga sir..