Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 10 additions & 138 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,149 +1,21 @@
pipeline {
agent none
pipeline{
agent any

environment {
MAJOR_VERSION = 1
options{
buildDiscaarder(logRotation(numToKeep '2', archive '1'))
}

stages {
stage('Say Hello') {
agent any
stage('build'){
steps{

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: """<p>'${env.JOB_NAME} [${env.BUILD_NUMBER}]' Development Promoted to Master":</p>
<p>Check console output at &QUOT;<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>&QUOT;</p>""",
to: "brandon@linuxacademy.com"
)
}
sh 'ant -f build.xml'
}
}
}
post {
failure {
emailext(
subject: "${env.JOB_NAME} [${env.BUILD_NUMBER}] Failed!",
body: """<p>'${env.JOB_NAME} [${env.BUILD_NUMBER}]' Failed!":</p>
<p>Check console output at &QUOT;<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>&QUOT;</p>""",
to: "brandon@linuxacademy.com"
)
post{
always{
archive 'dist/*.jar'
}
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# java-project
Java Project for Jenkins Course
new test
149 changes: 149 additions & 0 deletions Real_Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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: """<p>'${env.JOB_NAME} [${env.BUILD_NUMBER}]' Development Promoted to Master":</p>
<p>Check console output at &QUOT;<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>&QUOT;</p>""",
to: "brandon@linuxacademy.com"
)
}
}
}
}
post {
failure {
emailext(
subject: "${env.JOB_NAME} [${env.BUILD_NUMBER}] Failed!",
body: """<p>'${env.JOB_NAME} [${env.BUILD_NUMBER}]' Failed!":</p>
<p>Check console output at &QUOT;<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>&QUOT;</p>""",
to: "brandon@linuxacademy.com"
)
}
}
}