Jenkins pipeline project

Youtube Link: Navigation for labs

Lab: This lab we will create three projects

-Lab1: Create a basic pipeline project for cowsay utitlity

  1. Click on Dashboard–> NewItem–> Project name “myfirstproj” –>Select pipeline–>Press ok

2. Under the pipeline script block

pipeline {
  agent any
   stages {
    stage('Hello') {
      steps {
       sh '/usr/games/cowsay "hello" '
     }
   }
 }
}

Click on “Build now” and check the build history

Lab2: Scripted pipeline example

Create a new item–>Name “scriptedpipeline–>select pipeline–> press ok

In pipeline scripting section

node {
// Define the label of the agent where you want to run the pipeline
//label 'mylabel'
stage('Checkout') {
// Checkout code from the Git repository
sh 'echo checking out'
}
stage('Build') {
// Build the Java application (replace with your build commands)
sh 'javac -version'
}
stage('Deploy') {
// Deploy the application (replace with your deployment commands)
sh 'echo "Deploying the application"'
}
}

Click on Build now and check the build history

Click on build #1, and check the replay option and run, It will execute all the steps

 

Lab3: Declarative pipeline

New Item–>Name declartivepipeline–>select pipeline–>press ok

In pipeline script block

pipeline {
agent any
stages {
  stage('Checkout') {
    steps {
// Checkout code from the Git repository
     sh 'echo checking out'
   }
  }
stage('Build') {
  steps {
// Build the Java application (replace with your build commands)
  sh 'javac -version'
 }
}
stage('Deploy') {
  steps {
  // Deploy the application (replace with your deployment commands)
   sh 'echo "Deploying the application"'
   }
  }
 }
}

Click on buildnow–>Check build history

Select the build –>Restart from stage–>select stage from dropdown–>Run

 

Declartive pipeline provide us , to restart from stage option

Assignment:

  1. Go in your git repo “myrepo”
  2. Create a “Jenkinsfile”
  3. Copy the code from lab 3
  4. checkin the code to github (using git add,commit and push
  5. Create a new pipeline and scripting block dropdown, select “pipeline with SCM”
  6. Mention your git repo and save .
  7. Run the build