Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated jenkinsfile with suggested edits #1

Open
wants to merge 1 commit into
base: archive-success-example
Choose a base branch
from
Open
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
71 changes: 33 additions & 38 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,81 +1,76 @@
pipeline {
options {
timeout(time: 5, unit: 'MINUTES')
buildDiscarder(logRotator(numToKeepStr: '5'))
skipDefaultCheckout()
}
agent none
    options { 
        timeout(time: 5, unit: 'MINUTES')
buildDiscarder(logRotator(numToKeepStr: '5')) 
        skipDefaultCheckout() 
    }
    agent none

artifactName='*.jar'
stages {
script {artifactName='*.jar'}
  
  stages {
stage('Checkout') {
agent { label 'docker-cloud' }
steps {
echo 'INFO - Retrieving Source'
// git 'https://github.com/jglick/simple-maven-project-with-tests.git'
checkout scm
checkout scm  // create a multi-branch project that only checks out this branch
gitShortCommit(7)
}
}
checkpoint 'after Checkout before Build'
stage('Build') {
steps {
 steps {
echo 'INFO - Starting Build phase'
sh 'mvn validate'
sh 'mvn compile'
sh 'mvn clean install'
}
// sh 'mvn compile'
sh 'mvn clean install' // clean install does a compile, so no reason to do compile, also runs unit tests
 }
}
checkpoint 'after Build before Test'
stage('Test') {
steps {
 steps {
echo 'INFO - Starting Test phase'
parallel(
"unit test": {
echo 'unit tests'
mvn test
mvn surefire-report:report // generate a maven unit test report using surefire
mvn surefire-report:report // generate a maven unit test report using surefire
// this is the path to your unit test report: your-project/target/site/surefire-report.html
},
"integration tests": {
echo 'integration tests'
mvn verify // generate a maven integration test report
}
"other tests": {
echo 'other tests'
junit '**/target/surefire-reports/TEST-*.xml' // generate a junit test report
archive 'target/*.jar'
mvn verify -fn    // generate a maven integration test report
junit '**/target/surefire-reports/TEST-*.xml'    // generate a junit test report
// archive 'target/*.jar' // i thought we were only going to archive on success, so this should just be a stash and the artifact for the todo-api should be *.war
}
)
}
 }
}
checkpoint 'after Test before Package'
stage('Package') {
steps {
 steps {
echo 'INFO - Starting Package phase'
sh 'mvn clean package'
stash name: 'artifactName', includes: '*.xml'
}
}
post {
success {
unstash 'artifactName'
archive "target/${artifactName}"
}
checkpoint 'after Package before Deploy'
stage('Deploy') {
steps {
 steps {
echo 'INFO - Starting Deploy phase'
sh 'mvn deploy'
//-------------------------------------------------------------
// sh 'mvn deploy' // this won't work until the todo-api pom is not configured to deploy
// sh """
// rm -rf ${somevalue}/webapps/ROOT // remove a directory and files without comfirmation
// mv -f ${somevalue} // move files from one directory to another without prompting
// cp -rf ${war} ${somevalue}/webapps/ROOT.war // copy files from one location to another without prompting
//   rm -rf ${somevalue}/webapps/ROOT                 // remove a directory and files without comfirmation
// mv -f ${somevalue}                               // move files from one directory to another without prompting
// cp -rf ${war} ${somevalue}/webapps/ROOT.war      // copy files from one location to another without prompting
// ${somevalue}/bin/startup.sh
// """
//-------------------------------------------------------------
}
}
}
post {
success {
unstash 'artifactName'
archive "target/${artifactName}"
}
}
}