From 166e0794d3e7805f4d8e0bf75870bf7aacbe9ccc Mon Sep 17 00:00:00 2001 From: tejaveturi Date: Fri, 14 Apr 2017 15:25:21 -0400 Subject: [PATCH 1/8] adding jenkins file --- Real_Jenkinsfile | 149 +++++++++++++++++++++++++++++++++++++++++++++++ src/Jenkinsfile | 12 ++++ 2 files changed, 161 insertions(+) create mode 100644 Real_Jenkinsfile create mode 100644 src/Jenkinsfile diff --git a/Real_Jenkinsfile b/Real_Jenkinsfile new file mode 100644 index 00000000..4ba477d3 --- /dev/null +++ b/Real_Jenkinsfile @@ -0,0 +1,149 @@ +pipeline { + agent none + + environment { + MAJOR_VERSION = 1 + } + + stages { + stage('Say Hello') { + agent any + + steps { + sayHello 'Awesome Student!' + } + } + stage('Printing Git Info') { + agent any + + steps { + script { + def myLib = new linuxacademy.git.gitStuff(); + + echo "${env.WORKSPACE}/.git" + + echo myLib.gitInfo("${env.WORKSPACE}/.git", 'branch') + + echo myLib.gitInfo("${env.WORKSPACE}/.git", 'commit') + } + } + } + stage('Git Information') { + agent any + + steps { + echo "My Branch Name: ${env.BRANCH_NAME}" + + script { + def myLib = new linuxacademy.git.gitStuff(); + + echo "My Commit: ${myLib.gitCommit("${env.WORKSPACE}/.git")}" + } + } + } + stage('Unit Tests') { + agent { + label 'apache' + } + steps { + sh 'ant -f test.xml -v' + junit 'reports/result.xml' + } + } + stage('build') { + agent { + label 'apache' + } + steps { + sh 'ant -f build.xml -v' + } + post { + success { + archiveArtifacts artifacts: 'dist/*.jar', fingerprint: true + } + } + } + stage('deploy') { + agent { + label 'apache' + } + steps { + sh "if ![ -d '/var/www/html/rectangles/all/${env.BRANCH_NAME}' ]; then mkdir /var/www/html/rectangles/all/${env.BRANCH_NAME}; fi" + sh "cp dist/rectangle_${env.MAJOR_VERSION}.${env.BUILD_NUMBER}.jar /var/www/html/rectangles/all/${env.BRANCH_NAME}/" + } + } + stage("Running on CentOS") { + agent { + label 'CentOS' + } + steps { + sh "wget http://brandon4231.mylabserver.com/rectangles/all/${env.BRANCH_NAME}/rectangle_${env.MAJOR_VERSION}.${env.BUILD_NUMBER}.jar" + sh "java -jar rectangle_${env.MAJOR_VERSION}.${env.BUILD_NUMBER}.jar 3 4" + } + } + stage("Test on Debian") { + agent { + docker 'openjdk:8u121-jre' + } + steps { + sh "wget http://brandon4231.mylabserver.com/rectangles/all/${env.BRANCH_NAME}/rectangle_${env.MAJOR_VERSION}.${env.BUILD_NUMBER}.jar" + sh "java -jar rectangle_${env.MAJOR_VERSION}.${env.BUILD_NUMBER}.jar 3 4" + } + } + stage('Promote to Green') { + agent { + label 'apache' + } + when { + branch 'master' + } + steps { + sh "cp /var/www/html/rectangles/all/${env.BRANCH_NAME}/rectangle_${env.MAJOR_VERSION}.${env.BUILD_NUMBER}.jar /var/www/html/rectangles/green/rectangle_${env.MAJOR_VERSION}.${env.BUILD_NUMBER}.jar" + } + } + stage('Promote Development Branch to Master') { + agent { + label 'apache' + } + when { + branch 'development' + } + steps { + echo "Stashing Any Local Changes" + sh 'git stash' + echo "Checking Out Development Branch" + sh 'git checkout development' + echo 'Checking Out Master Branch' + sh 'git pull origin' + sh 'git checkout master' + echo 'Merging Development into Master Branch' + sh 'git merge development' + echo 'Pushing to Origin Master' + sh 'git push origin master' + echo 'Tagging the Release' + sh "git tag rectangle-${env.MAJOR_VERSION}.${env.BUILD_NUMBER}" + sh "git push origin rectangle-${env.MAJOR_VERSION}.${env.BUILD_NUMBER}" + } + post { + success { + emailext( + subject: "${env.JOB_NAME} [${env.BUILD_NUMBER}] Development Promoted to Master", + body: """

'${env.JOB_NAME} [${env.BUILD_NUMBER}]' Development Promoted to Master":

+

Check console output at "${env.JOB_NAME} [${env.BUILD_NUMBER}]"

""", + to: "brandon@linuxacademy.com" + ) + } + } + } + } + post { + failure { + emailext( + subject: "${env.JOB_NAME} [${env.BUILD_NUMBER}] Failed!", + body: """

'${env.JOB_NAME} [${env.BUILD_NUMBER}]' Failed!":

+

Check console output at "${env.JOB_NAME} [${env.BUILD_NUMBER}]"

""", + to: "brandon@linuxacademy.com" + ) + } + } +} diff --git a/src/Jenkinsfile b/src/Jenkinsfile new file mode 100644 index 00000000..62a212e4 --- /dev/null +++ b/src/Jenkinsfile @@ -0,0 +1,12 @@ +pipeline{ + agent any + + stages { + stage('build'){ + sh 'ant -f build.xml' + + } + } + + +} From 17f5a69b75a6d9da802f2e64ce5e15b7e1822fe0 Mon Sep 17 00:00:00 2001 From: tejaveturi Date: Fri, 14 Apr 2017 15:26:59 -0400 Subject: [PATCH 2/8] jenkins file --- Jenkinsfile | 147 ++---------------------------------------------- src/Jenkinsfile | 2 +- 2 files changed, 6 insertions(+), 143 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4ba477d3..0daa7282 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,149 +1,12 @@ -pipeline { - agent none - - environment { - MAJOR_VERSION = 1 - } +pipeline{ + agent any stages { - stage('Say Hello') { - agent any - - steps { - sayHello 'Awesome Student!' - } - } - stage('Printing Git Info') { - agent any - - steps { - script { - def myLib = new linuxacademy.git.gitStuff(); + stage('build'){ + sh 'ant -f build.xml' - echo "${env.WORKSPACE}/.git" - - echo myLib.gitInfo("${env.WORKSPACE}/.git", 'branch') - - echo myLib.gitInfo("${env.WORKSPACE}/.git", 'commit') - } - } } - stage('Git Information') { - agent any - - steps { - echo "My Branch Name: ${env.BRANCH_NAME}" + } - script { - def myLib = new linuxacademy.git.gitStuff(); - echo "My Commit: ${myLib.gitCommit("${env.WORKSPACE}/.git")}" - } - } - } - stage('Unit Tests') { - agent { - label 'apache' - } - steps { - sh 'ant -f test.xml -v' - junit 'reports/result.xml' - } - } - stage('build') { - agent { - label 'apache' - } - steps { - sh 'ant -f build.xml -v' - } - post { - success { - archiveArtifacts artifacts: 'dist/*.jar', fingerprint: true - } - } - } - stage('deploy') { - agent { - label 'apache' - } - steps { - sh "if ![ -d '/var/www/html/rectangles/all/${env.BRANCH_NAME}' ]; then mkdir /var/www/html/rectangles/all/${env.BRANCH_NAME}; fi" - sh "cp dist/rectangle_${env.MAJOR_VERSION}.${env.BUILD_NUMBER}.jar /var/www/html/rectangles/all/${env.BRANCH_NAME}/" - } - } - stage("Running on CentOS") { - agent { - label 'CentOS' - } - steps { - sh "wget http://brandon4231.mylabserver.com/rectangles/all/${env.BRANCH_NAME}/rectangle_${env.MAJOR_VERSION}.${env.BUILD_NUMBER}.jar" - sh "java -jar rectangle_${env.MAJOR_VERSION}.${env.BUILD_NUMBER}.jar 3 4" - } - } - stage("Test on Debian") { - agent { - docker 'openjdk:8u121-jre' - } - steps { - sh "wget http://brandon4231.mylabserver.com/rectangles/all/${env.BRANCH_NAME}/rectangle_${env.MAJOR_VERSION}.${env.BUILD_NUMBER}.jar" - sh "java -jar rectangle_${env.MAJOR_VERSION}.${env.BUILD_NUMBER}.jar 3 4" - } - } - stage('Promote to Green') { - agent { - label 'apache' - } - when { - branch 'master' - } - steps { - sh "cp /var/www/html/rectangles/all/${env.BRANCH_NAME}/rectangle_${env.MAJOR_VERSION}.${env.BUILD_NUMBER}.jar /var/www/html/rectangles/green/rectangle_${env.MAJOR_VERSION}.${env.BUILD_NUMBER}.jar" - } - } - stage('Promote Development Branch to Master') { - agent { - label 'apache' - } - when { - branch 'development' - } - steps { - echo "Stashing Any Local Changes" - sh 'git stash' - echo "Checking Out Development Branch" - sh 'git checkout development' - echo 'Checking Out Master Branch' - sh 'git pull origin' - sh 'git checkout master' - echo 'Merging Development into Master Branch' - sh 'git merge development' - echo 'Pushing to Origin Master' - sh 'git push origin master' - echo 'Tagging the Release' - sh "git tag rectangle-${env.MAJOR_VERSION}.${env.BUILD_NUMBER}" - sh "git push origin rectangle-${env.MAJOR_VERSION}.${env.BUILD_NUMBER}" - } - post { - success { - emailext( - subject: "${env.JOB_NAME} [${env.BUILD_NUMBER}] Development Promoted to Master", - body: """

'${env.JOB_NAME} [${env.BUILD_NUMBER}]' Development Promoted to Master":

-

Check console output at "${env.JOB_NAME} [${env.BUILD_NUMBER}]"

""", - to: "brandon@linuxacademy.com" - ) - } - } - } - } - post { - failure { - emailext( - subject: "${env.JOB_NAME} [${env.BUILD_NUMBER}] Failed!", - body: """

'${env.JOB_NAME} [${env.BUILD_NUMBER}]' Failed!":

-

Check console output at "${env.JOB_NAME} [${env.BUILD_NUMBER}]"

""", - to: "brandon@linuxacademy.com" - ) - } - } } diff --git a/src/Jenkinsfile b/src/Jenkinsfile index 62a212e4..0daa7282 100644 --- a/src/Jenkinsfile +++ b/src/Jenkinsfile @@ -7,6 +7,6 @@ pipeline{ } } - + } From 09331db3665fc2ee2f5866a5fbc28b8fa5a0d967 Mon Sep 17 00:00:00 2001 From: tejaveturi Date: Fri, 14 Apr 2017 15:50:33 -0400 Subject: [PATCH 3/8] pipeline corrected --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0daa7282..72e0b9d8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,10 +3,10 @@ pipeline{ stages { stage('build'){ - sh 'ant -f build.xml' + steps{ + sh 'ant -f build.xml' + } } } - - } From 829d75214f15c617939723fdfe388086f1f84eab Mon Sep 17 00:00:00 2001 From: tejaveturi Date: Fri, 14 Apr 2017 19:32:14 -0400 Subject: [PATCH 4/8] add archive step on Jenkinsfile --- Jenkinsfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 72e0b9d8..4db78781 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,5 +8,10 @@ pipeline{ sh 'ant -f build.xml' } } + post{ + always{ + archive 'dist/*.jar' + } + } } } From 27a15bc325cf8660aa025fd4ed73601e55c16679 Mon Sep 17 00:00:00 2001 From: tejaveturi Date: Fri, 14 Apr 2017 19:42:51 -0400 Subject: [PATCH 5/8] archive edited --- Jenkinsfile~ | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Jenkinsfile~ diff --git a/Jenkinsfile~ b/Jenkinsfile~ new file mode 100644 index 00000000..d2ba3bde --- /dev/null +++ b/Jenkinsfile~ @@ -0,0 +1,17 @@ +pipeline{ + agent any + + stages { + stage('build'){ + steps{ + + sh 'ant -f build.xml' + } + } + } + post{ + always{ + archive 'dist/*.jar' + } + } +} From 5a68a72cd2f5e0c2c3799ac3dfb6d7d954b6e6f3 Mon Sep 17 00:00:00 2001 From: tejaveturi Date: Fri, 14 Apr 2017 20:12:20 -0400 Subject: [PATCH 6/8] full archive --- Jenkinsfile | 2 +- src/Jenkinsfile | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 src/Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile index 4db78781..d2ba3bde 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,10 +8,10 @@ pipeline{ sh 'ant -f build.xml' } } + } post{ always{ archive 'dist/*.jar' } } - } } diff --git a/src/Jenkinsfile b/src/Jenkinsfile deleted file mode 100644 index 0daa7282..00000000 --- a/src/Jenkinsfile +++ /dev/null @@ -1,12 +0,0 @@ -pipeline{ - agent any - - stages { - stage('build'){ - sh 'ant -f build.xml' - - } - } - - -} From 766cb04840f89b1a4485fb5d3859ad643630a9e7 Mon Sep 17 00:00:00 2001 From: tejaveturi Date: Fri, 14 Apr 2017 20:21:36 -0400 Subject: [PATCH 7/8] test git hook --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0b52b34a..10b15fe6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # java-project Java Project for Jenkins Course + new test From 6c988af021c26d29816f2caafa64fd7305e6eb44 Mon Sep 17 00:00:00 2001 From: tejaveturi Date: Thu, 11 May 2017 11:54:09 -0400 Subject: [PATCH 8/8] build.xml changes --- Jenkinsfile | 4 ++++ Jenkinsfile~ | 17 ----------------- 2 files changed, 4 insertions(+), 17 deletions(-) delete mode 100644 Jenkinsfile~ diff --git a/Jenkinsfile b/Jenkinsfile index d2ba3bde..59e19bf9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,6 +1,10 @@ pipeline{ agent any + options{ + buildDiscaarder(logRotation(numToKeep '2', archive '1')) + } + stages { stage('build'){ steps{ diff --git a/Jenkinsfile~ b/Jenkinsfile~ deleted file mode 100644 index d2ba3bde..00000000 --- a/Jenkinsfile~ +++ /dev/null @@ -1,17 +0,0 @@ -pipeline{ - agent any - - stages { - stage('build'){ - steps{ - - sh 'ant -f build.xml' - } - } - } - post{ - always{ - archive 'dist/*.jar' - } - } -}