Task For DevOps Engineer
Task For DevOps Engineer
set2
bild
docker login
create repo
public or private
manual process
steps{
script{
}
Write deployment for kubernites
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 4
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: give the continer name
image: name of continer :latest
ports:
- containerPort: 8080
pipeline{
agent any
tools{
jdk 'jdk17'
nodejs 'node16'
}
environment {
SCANNER_HOME=tool 'sonar-scanner'
GIT_REPO_NAME = ""
GIT_USER_NAME = "" # change your Github Username here
}
steps {
// Use Maven to build and run JUnit tests
script {
def mavenHome = tool 'Maven' dir change
sh "${mavenHome}/bin/mvn clean test"
}
}
post {
always {
// Publish JUnit test results
junit 'target/surefire-reports/*.xml'
}
}
}
}
} Add junit test install plugin in we
stages {
stage('clean workspace'){
steps{
cleanWs()
}
}
}
}
Code qulaty puroues
stage("Sonarqube Analysis "){
steps{
withSonarQubeEnv('sonar-server') {
sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=TetrisVersion2.0 \
-Dsonar.projectKey=TetrisVersion2.0 '''
}
}
}
stage("quality gate"){
steps {
script {
waitForQualityGate abortPipeline: false, credentialsId: 'Sonar-token'
}
}
}
stage('Install Dependencies') { piojects dependences
steps {
sh "npm install"
}
}
steps{
script{
}
Image scan
stage("TRIVY"){
steps{
sh "trivy image :latest > trivyimage.txt" hear we scan the image in 2 time once build and push
Irepo again we scan it
stage('Checkout Code') {
steps {
git branch: 'main', url: '' /deployment file is we keep another repo we call hear
steps {
script {
withCredentials([string(credentialsId: 'github', variable: 'GITHUB_TOKEN')]) {
NEW_IMAGE_NAME = "sevenajay/tetrisv2:latest" #update your image here
sh "sed -i 's|image: .*|image: $NEW_IMAGE_NAME|' deployment.yml"
sh 'git add deployment.yml'
sh "git commit -m 'Update deployment image to $NEW_IMAGE_NAME'"
sh "git push
https://${GITHUB_TOKEN}@github.com/${GIT_USER_NAME}/${GIT_REPO_NAME} HEAD:main" image is
automaticallt update in the git repo
it gtopsway
}
}
}
}
}
}
Integrating git wth Jenkins
Step2 :
Crate Jenkins pliple job write script in Jenkins file -or writtin Jenkins script inside the jinks