Skip to content

Latest commit

 

History

History
179 lines (91 loc) · 4.45 KB

File metadata and controls

179 lines (91 loc) · 4.45 KB

Example scripted pipeline-1: Build on any available node.

node{

  stage("checkout the code"){

    println "from build stage"

  }
  
}

Example scripted pipeline-2: Build on any available node

node("node name or lable"){

  stage("checkout the code"){

    println "from build stage"

  }
  stage("Build"){

    println "from build stage"

  }

  stage("sonar"){

    println "from sonar stage"
  }

  stage("deploy to nexus"){

    println "from deploy stage"
  }

  stage("deploy to server"){

    println "from deploy stage"
  }

}

Example-3: Build on any available node (but below script compatible to Linux OS).

    node{

      stage("clone the code"){

        println "git cloning the code"

        git branch: 'web', credentialsId: 'jengitub', url: 'https://github.com/venkatasykam/DevOpsWebApp.git'

        println "git cloning completed"

      }

      stage("maven build"){

        println "maven build"

        println "build version(in pipeline script): ${params.releaseVersion}"

        sh'''

            echo "build version(inside the sh block): ${releaseVersion}"

            "/root/apache-maven-3.8.1/bin/mvn" clean install -DreleaseVersion=${releaseVersion}

            echo "====== Maven Build Successful============="

        '''

        //bat 'java -version'

        //bat 'mvn clean install'

      }

    }

Example-4: Build on any available node (below script is compatible to windows only - but make sure java, maven, git is already installed on jenkins windows node). Configure git path on windows as shown below - Manage Jenkins >> Global Tool Configuration >> Add git and the path (you can ignore the red color errors)

image

Generate Pipeline script

image

image

      node("maven-windows"){

          stage("clone the code"){

            println "git cloning the code"

            //git branch: 'web', credentialsId: 'jengitub', url: 'https://github.com/venkatasykam/DevOpsWebApp.git'

            checkout([$class: 'GitSCM', branches: [[name: '*/web']], extensions: [], gitTool: 'Git_Windows', userRemoteConfigs: [[credentialsId: 'jengitub', url: 'https://github.com/venkatasykam/DevOpsWebApp.git']]])

            println "git cloning completed"

          }

          stage("maven build"){

            println "maven build"

            println "build version(in pipeline script): ${params.releaseVersion}"

            bat 'java -version'

            bat ' "C:\\ProgramData\\chocolatey\\lib\\maven\\apache-maven-3.8.2\\bin\\mvn" clean install -DreleaseVersion=%releaseVersion% '

          }

        }

Example-5:

      node("maven"){

          stage("clone the code"){

            println "git cloning the code"

             if (isUnix()) {

                git branch: 'web', credentialsId: 'jengitub', url: 'https://github.com/venkatasykam/DevOpsWebApp.git'

             }else{

                checkout([$class: 'GitSCM', branches: [[name: '*/web']], extensions: [], gitTool: 'Git_Windows', userRemoteConfigs: [[credentialsId: 'jengitub', url: 'https://github.com/venkatasykam/DevOpsWebApp.git']]])
             }
            println "git cloning completed"

          }

          stage("maven build"){

            println "maven build"

            println "build version(in pipeline script): ${params.releaseVersion}"

            if (isUnix()) {
                sh'''

                    echo "build version(inside the sh block): ${releaseVersion}"

                    "/root/apache-maven-3.8.1/bin/mvn" clean install -DreleaseVersion=${releaseVersion}

                    echo "====== Maven Build Successful============="

                '''
            }else{

                bat 'java -version'

                bat ' "C:\\ProgramData\\chocolatey\\lib\\maven\\apache-maven-3.8.2\\bin\\mvn" clean install -DreleaseVersion=%releaseVersion% '
            }
          }

        }