|
| 1 | +Source code for WebCalculator app is at |
| 2 | + |
| 3 | +https://github.com/Sonal0409/JavaWebCalculator.git |
| 4 | + |
| 5 | + |
| 6 | +Create 2 new ec2-instance and name them as QAServer & prodServer. |
| 7 | + |
| 8 | +Go to Jenkins Master (name: GIT30MAR) |
| 9 | + |
| 10 | +Connect master to QAServer |
| 11 | +Connect master to prodServer |
| 12 | + |
| 13 | +Follow the below steps: |
| 14 | + |
| 15 | +LINUX SLAVE |
| 16 | +************************* |
| 17 | +create root directory |
| 18 | + |
| 19 | +cd /tmp |
| 20 | +mkdir jenkisndir |
| 21 | + |
| 22 | +give permission to the directory |
| 23 | + |
| 24 | +sudo chmod -R 777 /tmp/jenkinsdir |
| 25 | + |
| 26 | +Go to master |
| 27 | +************* |
| 28 | + |
| 29 | +Go to node |
| 30 | + |
| 31 | +give following informtion under Launch Method |
| 32 | + |
| 33 | +how to connect to master- select ssh |
| 34 | + |
| 35 | +host: private ip |
| 36 | + |
| 37 | +provide credentials |
| 38 | + |
| 39 | +also set |
| 40 | +Host key verfication as: |
| 41 | +Non verifying Verification startegy |
| 42 | + |
| 43 | +Save it. |
| 44 | + |
| 45 | +*************************** |
| 46 | + |
| 47 | +Create a new pipeline job : QApipelineJob |
| 48 | + |
| 49 | +Write the following pipeline as code and give Agent label as qa_Server |
| 50 | + |
| 51 | +pipeline{ |
| 52 | + |
| 53 | + tools{ |
| 54 | + jdk 'myjava' |
| 55 | + maven 'mymaven' |
| 56 | + } |
| 57 | + agent {label 'qa_Server'} |
| 58 | + stages{ |
| 59 | + stage('checkout'){ |
| 60 | + steps{ |
| 61 | + git branch: 'qa', url: 'https://github.com/sonal04devops/JavaWebCalculator.git' |
| 62 | + } |
| 63 | + } |
| 64 | + stage('Compile'){ |
| 65 | + |
| 66 | + steps{ |
| 67 | + echo 'compiling..' |
| 68 | + sh 'mvn compile' |
| 69 | + } |
| 70 | + } |
| 71 | + stage('UnitTest'){ |
| 72 | + |
| 73 | + steps{ |
| 74 | + sh 'mvn test' |
| 75 | + } |
| 76 | + post { |
| 77 | + success { |
| 78 | + junit 'target/surefire-reports/*.xml' |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + stage('Package'){ |
| 83 | + |
| 84 | + steps{ |
| 85 | + sh 'mvn package' |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | +} |
| 90 | +} |
| 91 | + |
| 92 | +Save the job and Build the job |
| 93 | +************************************************* |
| 94 | + |
| 95 | +Create a new pipeline job : QApipelineJob |
| 96 | + |
| 97 | +Write the following pipeline as code and give Agent label as prod_Server |
| 98 | + |
| 99 | +pipeline{ |
| 100 | + |
| 101 | + tools{ |
| 102 | + jdk 'myjava' |
| 103 | + maven 'mymaven' |
| 104 | + } |
| 105 | + agent {label 'prod_server'} |
| 106 | + stages{ |
| 107 | + stage('checkout'){ |
| 108 | + steps{ |
| 109 | + git 'https://github.com/sonal04devops/JavaWebCalculator.git' |
| 110 | + } |
| 111 | + } |
| 112 | + stage('Compile'){ |
| 113 | + |
| 114 | + steps{ |
| 115 | + echo 'compiling..' |
| 116 | + sh 'mvn compile' |
| 117 | + } |
| 118 | + } |
| 119 | + stage('UnitTest'){ |
| 120 | + |
| 121 | + steps{ |
| 122 | + sh 'mvn test' |
| 123 | + } |
| 124 | + post { |
| 125 | + success { |
| 126 | + junit 'target/surefire-reports/*.xml' |
| 127 | + } |
| 128 | + } |
| 129 | + } |
| 130 | + stage('Package'){ |
| 131 | + |
| 132 | + steps{ |
| 133 | + sh 'mvn package' |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | +} |
| 138 | +} |
| 139 | + |
| 140 | +****************************************************** |
| 141 | + |
| 142 | +Otherwise you can create Jenkins files with pipeline code in respective branches (Master & QA) and then execute the Job in Jenkins. |
| 143 | + |
| 144 | +You can also connect QA and prod jobs to get executed one after the other. This will be automatic triggering of prodServer job. |
| 145 | + |
| 146 | + |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | +******************************************* |
| 151 | + |
| 152 | +Parameters |
| 153 | +In order to support the wide variety of use-cases Pipeline authors may have, the agent section supports a few different types of parameters. These parameters can be applied at the top-level of the pipeline block, or within each stage directive. |
| 154 | + |
| 155 | +any |
| 156 | +Execute the Pipeline, or stage, on any available agent. For example: agent any |
| 157 | + |
| 158 | +none |
| 159 | +When applied at the top-level of the pipeline block no global agent will be allocated for the entire Pipeline run and each stage section will need to contain its own agent section. For example: agent none |
| 160 | + |
| 161 | +label |
| 162 | +Execute the Pipeline, or stage, on an agent available in the Jenkins environment with the provided label. For example: agent { label 'my-defined-label' } |
| 163 | + |
| 164 | +Label conditions can also be used. For example: agent { label 'my-label1 && my-label2' } or agent { label 'my-label1 || my-label2' } |
| 165 | + |
| 166 | +node |
| 167 | +agent { node { label 'labelName' } } behaves the same as agent { label 'labelName' }, but node allows for additional options (such as customWorkspace). |
| 168 | + |
| 169 | + |
| 170 | + |
0 commit comments