From f57288cfa2819db5c7cbf871ab81641717fd4899 Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 10:28:19 -0400 Subject: [PATCH 01/29] switched from node to pipeline --- Jenkinsfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 40bdee7..4cac44a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,8 @@ -node { - tools {"org.jenkinsci.plugins.terraform.TerraformInstallation" "terraform-0.11.10"} +pipeline { + agent any + tools { + "org.jenkinsci.plugins.terraform.TerraformInstallation" "terraform-0.11.10" + } environment { TF_HOME = tool('terraform-0.11.10') From 3d3c11609b09bfaf1e064543074788bbf64015a4 Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 10:33:24 -0400 Subject: [PATCH 02/29] tested jenkinsfile read --- Jenkinsfile | 86 ++++++++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4cac44a..cd09e56 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,58 +14,58 @@ pipeline { echo "workspace directory is ${workspace}" - stage('checkout') { - checkout scm - } + // stage('checkout') { + // checkout scm + // } - stage('check java') { - sh "java -version" - } + // stage('check java') { + // sh "java -version" + // } - script { - version = sh ( - script: "./gradlew properties -q | grep \"^version:\" | awk '{print \$2}'", - returnStdout: true - ).trim() - sh "echo Building project in version: $version" - } + // script { + // version = sh ( + // script: "./gradlew properties -q | grep \"^version:\" | awk '{print \$2}'", + // returnStdout: true + // ).trim() + // sh "echo Building project in version: $version" + // } - stage('clean') { - sh "chmod +x gradlew" - sh "./gradlew clean --no-daemon" - } + // stage('clean') { + // sh "chmod +x gradlew" + // sh "./gradlew clean --no-daemon" + // } - stage('build') { - sh "./gradlew npm_install -Pprod -PnodeInstall --no-daemon" - } + // stage('build') { + // sh "./gradlew npm_install -Pprod -PnodeInstall --no-daemon" + // } - stage('backend tests') { - try { - sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" - } catch(err) { - throw err - } finally { - junit '**/build/**/TEST-*.xml' } } + // stage('backend tests') { + // try { + // sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" + // } catch(err) { + // throw err + // } finally { + // junit '**/build/**/TEST-*.xml' } } - stage('frontend tests') { - try { - sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" - } catch(err) { - throw err - } finally { - junit '**/build/test-results/TESTS-*.xml' - } - } + // stage('frontend tests') { + // try { + // sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" + // } catch(err) { + // throw err + // } finally { + // junit '**/build/test-results/TESTS-*.xml' + // } + // } - stage('packaging') { - sh "./gradlew bootJar -x test -Pprod -PnodeInstall --no-daemon" - archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true - } + // stage('packaging') { + // sh "./gradlew bootJar -x test -Pprod -PnodeInstall --no-daemon" + // archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true + // } - stage ('Publish') { - nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] - } + // stage ('Publish') { + // nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] + // } stage('terraform init') { dir('./terraform/prod'){ From c57ebf1418f24bbcf757a04cdb1de29d45d0a175 Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 10:59:54 -0400 Subject: [PATCH 03/29] working on the correct jenkinsfile this time --- Jenkinsfile | 86 ++++++++++++++++++++--------------------- Jenkinsfile.integration | 50 +++++++++++++++++++++++- 2 files changed, 92 insertions(+), 44 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cd09e56..07ae4fa 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,58 +14,58 @@ pipeline { echo "workspace directory is ${workspace}" - // stage('checkout') { - // checkout scm - // } + stage('checkout') { + checkout scm + } - // stage('check java') { - // sh "java -version" - // } + stage('check java') { + sh "java -version" + } - // script { - // version = sh ( - // script: "./gradlew properties -q | grep \"^version:\" | awk '{print \$2}'", - // returnStdout: true - // ).trim() - // sh "echo Building project in version: $version" - // } + script { + version = sh ( + script: "./gradlew properties -q | grep \"^version:\" | awk '{print \$2}'", + returnStdout: true + ).trim() + sh "echo Building project in version: $version" + } - // stage('clean') { - // sh "chmod +x gradlew" - // sh "./gradlew clean --no-daemon" - // } + stage('clean') { + sh "chmod +x gradlew" + sh "./gradlew clean --no-daemon" + } - // stage('build') { - // sh "./gradlew npm_install -Pprod -PnodeInstall --no-daemon" - // } + stage('build') { + sh "./gradlew npm_install -Pprod -PnodeInstall --no-daemon" + } - // stage('backend tests') { - // try { - // sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" - // } catch(err) { - // throw err - // } finally { - // junit '**/build/**/TEST-*.xml' } } + stage('backend tests') { + try { + sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" + } catch(err) { + throw err + } finally { + junit '**/build/**/TEST-*.xml' } } - // stage('frontend tests') { - // try { - // sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" - // } catch(err) { - // throw err - // } finally { - // junit '**/build/test-results/TESTS-*.xml' - // } - // } + stage('frontend tests') { + try { + sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" + } catch(err) { + throw err + } finally { + junit '**/build/test-results/TESTS-*.xml' + } + } - // stage('packaging') { - // sh "./gradlew bootJar -x test -Pprod -PnodeInstall --no-daemon" - // archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true - // } + stage('packaging') { + sh "./gradlew bootJar -x test -Pprod -PnodeInstall --no-daemon" + archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true + } - // stage ('Publish') { - // nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] - // } + stage ('Publish') { + nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] + } stage('terraform init') { dir('./terraform/prod'){ diff --git a/Jenkinsfile.integration b/Jenkinsfile.integration index e7657ad..4472e5b 100644 --- a/Jenkinsfile.integration +++ b/Jenkinsfile.integration @@ -1,5 +1,18 @@ -node { +pipeline { + agent any + tools { + "org.jenkinsci.plugins.terraform.TerraformInstallation" "terraform-0.11.10" + } + + environment { + TF_HOME = tool('terraform-0.11.10') + TF_IN_AUTOMATION = "true" + PATH = "$TF_HOME:$PATH" + ACCESS_KEY = credentials('jenkins-aws-secret-key-id') + SECRET_KEY = credentials('jenkins-aws-secret-access-key') + } + echo "workspace directory is ${workspace}" stage('checkout') { @@ -60,4 +73,39 @@ node { stage ('Publish') { nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] } + + stage('terraform init') { + dir('./terraform/prod'){ + sh "echo 'Initializing Terraform'" + sh "terraform init -input=false" + } + } + + stage('terraform plan'){ + dir('./terraform/prod'){ + sh "echo 'Planning Terraform Build'" + sh "terraform plan -var 'access_key=$ACCESS_KEY' -var 'secret_key=$SECRET_KEY'" + } + } + + stage('terraform apply'){ + steps { + script{ + def apply = false + try { + input message: 'Can you please confirm the apply', ok: 'Ready to Apply the Config' + apply = true + } catch (err) { + apply = false + currentBuild.result = 'UNSTABLE' + } + if(apply){ + dir('./terraform/prod'){ + sh "echo 'Applying Terraform'" + sh 'terraform apply --auto-approve' + } + } + } + } + } } From f36daa6890e2a9e56cf598d08a62e08640d35f07 Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 11:01:15 -0400 Subject: [PATCH 04/29] moved workspace dec --- Jenkinsfile.integration | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile.integration b/Jenkinsfile.integration index 4472e5b..7f029c0 100644 --- a/Jenkinsfile.integration +++ b/Jenkinsfile.integration @@ -12,11 +12,12 @@ pipeline { ACCESS_KEY = credentials('jenkins-aws-secret-key-id') SECRET_KEY = credentials('jenkins-aws-secret-access-key') } + - echo "workspace directory is ${workspace}" stage('checkout') { checkout scm + echo "workspace directory is ${workspace}" } stage('check java') { From eb6c1d2cbcfa01ed6490932fe19a1720414ff41f Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 11:02:48 -0400 Subject: [PATCH 05/29] added stages wrapper --- Jenkinsfile.integration | 152 ++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 75 deletions(-) diff --git a/Jenkinsfile.integration b/Jenkinsfile.integration index 7f029c0..055dd0e 100644 --- a/Jenkinsfile.integration +++ b/Jenkinsfile.integration @@ -13,100 +13,102 @@ pipeline { SECRET_KEY = credentials('jenkins-aws-secret-access-key') } - - - stage('checkout') { - checkout scm - echo "workspace directory is ${workspace}" - } + stages{ + stage('checkout') { + checkout scm + echo "workspace directory is ${workspace}" + } - stage('check java') { - sh "java -version" - } + stage('check java') { + sh "java -version" + } - script { - version = sh ( - script: "./gradlew properties -q | grep \"^version:\" | awk '{print \$2}'", - returnStdout: true - ).trim() - sh "echo Building project in version: $version" - } + script { + version = sh ( + script: "./gradlew properties -q | grep \"^version:\" | awk '{print \$2}'", + returnStdout: true + ).trim() + sh "echo Building project in version: $version" + } - stage('clean') { - sh "chmod +x gradlew" - sh "./gradlew clean --no-daemon" - } + stage('clean') { + sh "chmod +x gradlew" + sh "./gradlew clean --no-daemon" + } - stage('build') { - sh "./gradlew npm_install -Pprod -PnodeInstall --no-daemon" - } + stage('build') { + sh "./gradlew npm_install -Pprod -PnodeInstall --no-daemon" + } - stage('quality analysis') { - withSonarQubeEnv('sonarqube') { - sh "./gradlew sonarqube --no-daemon -PnodeInstall -Pprod" + stage('quality analysis') { + withSonarQubeEnv('sonarqube') { + sh "./gradlew sonarqube --no-daemon -PnodeInstall -Pprod" + } } - } - stage('backend tests') { + stage('backend tests') { + try { + sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" + } catch(err) { + throw err + } finally { + junit '**/build/**/TEST-*.xml' } } + + stage('frontend tests') { try { - sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" - } catch(err) { - throw err - } finally { - junit '**/build/**/TEST-*.xml' } } - - stage('frontend tests') { - try { - sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" - } catch(err) { - throw err - } finally { - junit '**/build/test-results/TESTS-*.xml' + sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" + } catch(err) { + throw err + } finally { + junit '**/build/test-results/TESTS-*.xml' + } } - } - stage('packaging') { - sh "./gradlew bootJar -x test -Pprod -PnodeInstall --no-daemon" - archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true - } + stage('packaging') { + sh "./gradlew bootJar -x test -Pprod -PnodeInstall --no-daemon" + archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true + } - stage ('Publish') { - nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] - } + stage ('Publish') { + nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] + } - stage('terraform init') { - dir('./terraform/prod'){ - sh "echo 'Initializing Terraform'" - sh "terraform init -input=false" + stage('terraform init') { + dir('./terraform/prod'){ + sh "echo 'Initializing Terraform'" + sh "terraform init -input=false" + } } - } - stage('terraform plan'){ - dir('./terraform/prod'){ - sh "echo 'Planning Terraform Build'" - sh "terraform plan -var 'access_key=$ACCESS_KEY' -var 'secret_key=$SECRET_KEY'" + stage('terraform plan'){ + dir('./terraform/prod'){ + sh "echo 'Planning Terraform Build'" + sh "terraform plan -var 'access_key=$ACCESS_KEY' -var 'secret_key=$SECRET_KEY'" + } } - } - stage('terraform apply'){ - steps { - script{ - def apply = false - try { - input message: 'Can you please confirm the apply', ok: 'Ready to Apply the Config' - apply = true - } catch (err) { - apply = false - currentBuild.result = 'UNSTABLE' - } - if(apply){ - dir('./terraform/prod'){ - sh "echo 'Applying Terraform'" - sh 'terraform apply --auto-approve' + stage('terraform apply'){ + steps { + script{ + def apply = false + try { + input message: 'Can you please confirm the apply', ok: 'Ready to Apply the Config' + apply = true + } catch (err) { + apply = false + currentBuild.result = 'UNSTABLE' + } + if(apply){ + dir('./terraform/prod'){ + sh "echo 'Applying Terraform'" + sh 'terraform apply --auto-approve' + } } } } } - } + } + + } From 0eeac546d35e6d9d412fd55196fdb586accda48a Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 11:29:49 -0400 Subject: [PATCH 06/29] updated jenkinsfile.integration --- Jenkinsfile.integration | 103 ++++++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 42 deletions(-) diff --git a/Jenkinsfile.integration b/Jenkinsfile.integration index 055dd0e..7c502f3 100644 --- a/Jenkinsfile.integration +++ b/Jenkinsfile.integration @@ -15,71 +15,92 @@ pipeline { stages{ stage('checkout') { - checkout scm - echo "workspace directory is ${workspace}" + steps { + checkout scm + echo "workspace directory is ${workspace}" + } } stage('check java') { - sh "java -version" + steps { + sh "java -version" + } } - script { - version = sh ( - script: "./gradlew properties -q | grep \"^version:\" | awk '{print \$2}'", - returnStdout: true - ).trim() - sh "echo Building project in version: $version" + stage('get project version') { + steps { + script { + version = sh ( + script: "./gradlew properties -q | grep \"^version:\" | awk '{print \$2}'", + returnStdout: true + ).trim() + sh "echo Building project in version: $version" + } + } } - - + stage('clean') { - sh "chmod +x gradlew" - sh "./gradlew clean --no-daemon" + steps { + sh "chmod +x gradlew" + sh "./gradlew clean --no-daemon" + } } stage('build') { - sh "./gradlew npm_install -Pprod -PnodeInstall --no-daemon" + steps { + sh "./gradlew npm_install -Pprod -PnodeInstall --no-daemon" + } } stage('quality analysis') { - withSonarQubeEnv('sonarqube') { - sh "./gradlew sonarqube --no-daemon -PnodeInstall -Pprod" + steps { + withSonarQubeEnv('sonarqube') { + sh "./gradlew sonarqube --no-daemon -PnodeInstall -Pprod" + } } } stage('backend tests') { - try { - sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" - } catch(err) { - throw err - } finally { - junit '**/build/**/TEST-*.xml' } } + steps { + try { + sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" + } catch(err) { + throw err + } finally { + junit '**/build/**/TEST-*.xml' } + } + } + - stage('frontend tests') { - try { - sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" - } catch(err) { - throw err - } finally { - junit '**/build/test-results/TESTS-*.xml' - } + stage('frontend tests') { + steps { + try { + sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" + } catch(err) { + throw err + } finally { + junit '**/build/test-results/TESTS-*.xml' + } + } } stage('packaging') { - sh "./gradlew bootJar -x test -Pprod -PnodeInstall --no-daemon" - archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true + steps { + sh "./gradlew bootJar -x test -Pprod -PnodeInstall --no-daemon" + archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true + } } - stage ('Publish') { + stage ('Publish') { nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] - } + } - stage('terraform init') { - dir('./terraform/prod'){ - sh "echo 'Initializing Terraform'" - sh "terraform init -input=false" + stage('terraform init') { + dir('./terraform/prod'){ + sh "echo 'Initializing Terraform'" + sh "terraform init -input=false" + } } - } stage('terraform plan'){ dir('./terraform/prod'){ @@ -108,7 +129,5 @@ pipeline { } } } - } - - + } } From 5f2367199fbc53782ddd5361a881bde9b21a5692 Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 11:41:41 -0400 Subject: [PATCH 07/29] more updates to jenkinsfile --- Jenkinsfile.integration | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/Jenkinsfile.integration b/Jenkinsfile.integration index 7c502f3..25ee490 100644 --- a/Jenkinsfile.integration +++ b/Jenkinsfile.integration @@ -62,24 +62,27 @@ pipeline { stage('backend tests') { steps { - try { - sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" - } catch(err) { - throw err - } finally { - junit '**/build/**/TEST-*.xml' } + script { + try { + sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" + } catch(err) { + throw err + } finally { + junit '**/build/**/TEST-*.xml' } + } } } stage('frontend tests') { steps { - try { - sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" - } catch(err) { - throw err - } finally { - junit '**/build/test-results/TESTS-*.xml' + script { + try { + sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" + } catch(err) { + throw err + } finally { + junit '**/build/test-results/TESTS-*.xml' } } } } @@ -92,20 +95,26 @@ pipeline { } stage ('Publish') { - nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] + steps { + nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] + } } stage('terraform init') { + steps { dir('./terraform/prod'){ sh "echo 'Initializing Terraform'" sh "terraform init -input=false" } } + } stage('terraform plan'){ - dir('./terraform/prod'){ - sh "echo 'Planning Terraform Build'" - sh "terraform plan -var 'access_key=$ACCESS_KEY' -var 'secret_key=$SECRET_KEY'" + steps { + dir('./terraform/prod'){ + sh "echo 'Planning Terraform Build'" + sh "terraform plan -var 'access_key=$ACCESS_KEY' -var 'secret_key=$SECRET_KEY'" + } } } From 30872a51437d4ac9a6578a27b67af220358b18fc Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 13:10:19 -0400 Subject: [PATCH 08/29] working on env vars --- Jenkinsfile.integration | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile.integration b/Jenkinsfile.integration index 25ee490..96b146d 100644 --- a/Jenkinsfile.integration +++ b/Jenkinsfile.integration @@ -18,6 +18,7 @@ pipeline { steps { checkout scm echo "workspace directory is ${workspace}" + echo "${env.ACCESS_KEY}" } } @@ -113,7 +114,7 @@ pipeline { steps { dir('./terraform/prod'){ sh "echo 'Planning Terraform Build'" - sh "terraform plan -var 'access_key=$ACCESS_KEY' -var 'secret_key=$SECRET_KEY'" + sh "terraform plan -var 'access_key=${env.ACCESS_KEY}' -var 'secret_key=${env.SECRET_KEY}'" } } } From 4c53a5f702f7d3f543e90fdb2705189946ff726e Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 13:26:01 -0400 Subject: [PATCH 09/29] removed creds --- Jenkinsfile.integration | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Jenkinsfile.integration b/Jenkinsfile.integration index 96b146d..c8a0be3 100644 --- a/Jenkinsfile.integration +++ b/Jenkinsfile.integration @@ -18,7 +18,6 @@ pipeline { steps { checkout scm echo "workspace directory is ${workspace}" - echo "${env.ACCESS_KEY}" } } @@ -114,7 +113,7 @@ pipeline { steps { dir('./terraform/prod'){ sh "echo 'Planning Terraform Build'" - sh "terraform plan -var 'access_key=${env.ACCESS_KEY}' -var 'secret_key=${env.SECRET_KEY}'" + sh "terraform plan //-var 'access_key=${env.ACCESS_KEY}' -var 'secret_key=${env.SECRET_KEY}'" } } } From c0512334ad86a1c096ea7a17f024e362df377755 Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 13:34:49 -0400 Subject: [PATCH 10/29] fixed comment issue --- Jenkinsfile.integration | 152 ++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/Jenkinsfile.integration b/Jenkinsfile.integration index c8a0be3..00f6ebe 100644 --- a/Jenkinsfile.integration +++ b/Jenkinsfile.integration @@ -14,91 +14,91 @@ pipeline { } stages{ - stage('checkout') { - steps { - checkout scm - echo "workspace directory is ${workspace}" - } - } + // stage('checkout') { + // steps { + // checkout scm + // echo "workspace directory is ${workspace}" + // } + // } - stage('check java') { - steps { - sh "java -version" - } - } + // stage('check java') { + // steps { + // sh "java -version" + // } + // } - stage('get project version') { - steps { - script { - version = sh ( - script: "./gradlew properties -q | grep \"^version:\" | awk '{print \$2}'", - returnStdout: true - ).trim() - sh "echo Building project in version: $version" - } - } - } + // stage('get project version') { + // steps { + // script { + // version = sh ( + // script: "./gradlew properties -q | grep \"^version:\" | awk '{print \$2}'", + // returnStdout: true + // ).trim() + // sh "echo Building project in version: $version" + // } + // } + // } - stage('clean') { - steps { - sh "chmod +x gradlew" - sh "./gradlew clean --no-daemon" - } - } + // stage('clean') { + // steps { + // sh "chmod +x gradlew" + // sh "./gradlew clean --no-daemon" + // } + // } - stage('build') { - steps { - sh "./gradlew npm_install -Pprod -PnodeInstall --no-daemon" - } - } + // stage('build') { + // steps { + // sh "./gradlew npm_install -Pprod -PnodeInstall --no-daemon" + // } + // } - stage('quality analysis') { - steps { - withSonarQubeEnv('sonarqube') { - sh "./gradlew sonarqube --no-daemon -PnodeInstall -Pprod" - } - } - } + // stage('quality analysis') { + // steps { + // withSonarQubeEnv('sonarqube') { + // sh "./gradlew sonarqube --no-daemon -PnodeInstall -Pprod" + // } + // } + // } - stage('backend tests') { - steps { - script { - try { - sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" - } catch(err) { - throw err - } finally { - junit '**/build/**/TEST-*.xml' } - } - } - } + // stage('backend tests') { + // steps { + // script { + // try { + // sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" + // } catch(err) { + // throw err + // } finally { + // junit '**/build/**/TEST-*.xml' } + // } + // } + // } - stage('frontend tests') { - steps { - script { - try { - sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" - } catch(err) { - throw err - } finally { - junit '**/build/test-results/TESTS-*.xml' } - } - } - } + // stage('frontend tests') { + // steps { + // script { + // try { + // sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" + // } catch(err) { + // throw err + // } finally { + // junit '**/build/test-results/TESTS-*.xml' } + // } + // } + // } - stage('packaging') { - steps { - sh "./gradlew bootJar -x test -Pprod -PnodeInstall --no-daemon" - archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true - } - } + // stage('packaging') { + // steps { + // sh "./gradlew bootJar -x test -Pprod -PnodeInstall --no-daemon" + // archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true + // } + // } - stage ('Publish') { - steps { - nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] - } - } + // stage ('Publish') { + // steps { + // nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] + // } + // } stage('terraform init') { steps { @@ -113,7 +113,7 @@ pipeline { steps { dir('./terraform/prod'){ sh "echo 'Planning Terraform Build'" - sh "terraform plan //-var 'access_key=${env.ACCESS_KEY}' -var 'secret_key=${env.SECRET_KEY}'" + sh "terraform plan"//-var 'access_key=${env.ACCESS_KEY}' -var 'secret_key=${env.SECRET_KEY}'" } } } From 06d55423bcbf4a09cf692241ca8cb44a6bd78567 Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 13:47:43 -0400 Subject: [PATCH 11/29] fixed object type issue --- terraform/modules/ec2/variables.tf | 2 +- terraform/prod/main.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/modules/ec2/variables.tf b/terraform/modules/ec2/variables.tf index b3b8c08..bc0d412 100644 --- a/terraform/modules/ec2/variables.tf +++ b/terraform/modules/ec2/variables.tf @@ -12,7 +12,7 @@ variable "key" { } variable "security_groups" { - type = "list" + } variable "subnet_id" { diff --git a/terraform/prod/main.tf b/terraform/prod/main.tf index e9dd380..d96dfa1 100644 --- a/terraform/prod/main.tf +++ b/terraform/prod/main.tf @@ -25,7 +25,7 @@ module "ec2_server" { profile = "sts" instance_type = "t3.medium" - security_groups = ["${module.security_group.id}"] + security_groups = "${module.security_group.id}" subnet_id = "subnet-0a1f8963d08b10d8f" name = "dev_server" From f4b19a4a5e515f4bb0daaaee14a817728b866f2a Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 13:51:16 -0400 Subject: [PATCH 12/29] debugging version conflict --- Jenkinsfile.integration | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile.integration b/Jenkinsfile.integration index 00f6ebe..eaa925d 100644 --- a/Jenkinsfile.integration +++ b/Jenkinsfile.integration @@ -103,6 +103,7 @@ pipeline { stage('terraform init') { steps { dir('./terraform/prod'){ + sh "terraform --version" sh "echo 'Initializing Terraform'" sh "terraform init -input=false" } From 02c71a552dd4b8f1188f2e2717b5532ce708ad55 Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 14:14:26 -0400 Subject: [PATCH 13/29] added version constraints --- terraform/modules/ec2/main.tf | 1 + terraform/prod/main.tf | 1 + 2 files changed, 2 insertions(+) diff --git a/terraform/modules/ec2/main.tf b/terraform/modules/ec2/main.tf index 1d8d24b..3f74603 100644 --- a/terraform/modules/ec2/main.tf +++ b/terraform/modules/ec2/main.tf @@ -1,6 +1,7 @@ provider "aws" { profile = "${var.profile}" region = "${var.region}" + version = "2.14" } data "template_file" "init" { diff --git a/terraform/prod/main.tf b/terraform/prod/main.tf index d96dfa1..7fb9fc8 100644 --- a/terraform/prod/main.tf +++ b/terraform/prod/main.tf @@ -5,6 +5,7 @@ terraform { region = "us-east-1" profile = "sts" } + required_version = "0.11.10" } module "security_group" { source = "../modules/security_group" From 767e30e0cf89107d3f7ec64fa68b35a179bba47e Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 14:30:32 -0400 Subject: [PATCH 14/29] commented out infra creation --- Jenkinsfile.integration | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Jenkinsfile.integration b/Jenkinsfile.integration index eaa925d..4bdad5d 100644 --- a/Jenkinsfile.integration +++ b/Jenkinsfile.integration @@ -119,25 +119,25 @@ pipeline { } } - stage('terraform apply'){ - steps { - script{ - def apply = false - try { - input message: 'Can you please confirm the apply', ok: 'Ready to Apply the Config' - apply = true - } catch (err) { - apply = false - currentBuild.result = 'UNSTABLE' - } - if(apply){ - dir('./terraform/prod'){ - sh "echo 'Applying Terraform'" - sh 'terraform apply --auto-approve' - } - } - } - } - } + // stage('terraform apply'){ + // steps { + // script{ + // def apply = false + // try { + // input message: 'Can you please confirm the apply', ok: 'Ready to Apply the Config' + // apply = true + // } catch (err) { + // apply = false + // currentBuild.result = 'UNSTABLE' + // } + // if(apply){ + // dir('./terraform/prod'){ + // sh "echo 'Applying Terraform'" + // sh 'terraform apply --auto-approve' + // } + // } + // } + // } + // } } } From eb73dacc245e0d5153470bf3b404f99c50df0ae6 Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 14:31:33 -0400 Subject: [PATCH 15/29] removed version constrants --- terraform/prod/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/prod/main.tf b/terraform/prod/main.tf index 7fb9fc8..ca3527c 100644 --- a/terraform/prod/main.tf +++ b/terraform/prod/main.tf @@ -5,7 +5,7 @@ terraform { region = "us-east-1" profile = "sts" } - required_version = "0.11.10" + # required_version = "0.11.10" } module "security_group" { source = "../modules/security_group" From ca19d70a173975841adf0703e5ff0a4affb35110 Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 15:17:42 -0400 Subject: [PATCH 16/29] switching to tf.12 --- Jenkinsfile | 104 ---------------------- Jenkinsfile.integration | 192 ++++++++++++++++++++-------------------- terraform/prod/main.tf | 1 - 3 files changed, 96 insertions(+), 201 deletions(-) delete mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 07ae4fa..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,104 +0,0 @@ -pipeline { - agent any - tools { - "org.jenkinsci.plugins.terraform.TerraformInstallation" "terraform-0.11.10" - } - - environment { - TF_HOME = tool('terraform-0.11.10') - TF_IN_AUTOMATION = "true" - PATH = "$TF_HOME:$PATH" - ACCESS_KEY = credentials('jenkins-aws-secret-key-id') - SECRET_KEY = credentials('jenkins-aws-secret-access-key') - } - - echo "workspace directory is ${workspace}" - - stage('checkout') { - checkout scm - } - - stage('check java') { - sh "java -version" - } - - script { - version = sh ( - script: "./gradlew properties -q | grep \"^version:\" | awk '{print \$2}'", - returnStdout: true - ).trim() - sh "echo Building project in version: $version" - } - - stage('clean') { - sh "chmod +x gradlew" - sh "./gradlew clean --no-daemon" - } - - stage('build') { - sh "./gradlew npm_install -Pprod -PnodeInstall --no-daemon" - } - - - stage('backend tests') { - try { - sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" - } catch(err) { - throw err - } finally { - junit '**/build/**/TEST-*.xml' } } - - stage('frontend tests') { - try { - sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" - } catch(err) { - throw err - } finally { - junit '**/build/test-results/TESTS-*.xml' - } - } - - stage('packaging') { - sh "./gradlew bootJar -x test -Pprod -PnodeInstall --no-daemon" - archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true - } - - stage ('Publish') { - nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] - } - - stage('terraform init') { - dir('./terraform/prod'){ - sh "echo 'Initializing Terraform'" - sh "terraform init -input=false" - } - } - - stage('terraform plan'){ - dir('./terraform/prod'){ - sh "echo 'Planning Terraform Build'" - sh "terraform plan -var 'access_key=$ACCESS_KEY' -var 'secret_key=$SECRET_KEY'" - } - } - - stage('terraform apply'){ - steps { - script{ - def apply = false - try { - input message: 'Can you please confirm the apply', ok: 'Ready to Apply the Config' - apply = true - } catch (err) { - apply = false - currentBuild.result = 'UNSTABLE' - } - if(apply){ - dir('./terraform/prod'){ - sh "echo 'Applying Terraform'" - sh 'terraform apply --auto-approve' - } - } - } - } - } -} \ No newline at end of file diff --git a/Jenkinsfile.integration b/Jenkinsfile.integration index 4bdad5d..dfaa2fe 100644 --- a/Jenkinsfile.integration +++ b/Jenkinsfile.integration @@ -14,91 +14,91 @@ pipeline { } stages{ - // stage('checkout') { - // steps { - // checkout scm - // echo "workspace directory is ${workspace}" - // } - // } + // stage('checkout') { + // steps { + // checkout scm + // echo "workspace directory is ${workspace}" + // } + // } - // stage('check java') { - // steps { - // sh "java -version" - // } - // } + // stage('check java') { + // steps { + // sh "java -version" + // } + // } - // stage('get project version') { - // steps { - // script { - // version = sh ( - // script: "./gradlew properties -q | grep \"^version:\" | awk '{print \$2}'", - // returnStdout: true - // ).trim() - // sh "echo Building project in version: $version" - // } - // } - // } + // stage('get project version') { + // steps { + // script { + // version = sh ( + // script: "./gradlew properties -q | grep \"^version:\" | awk '{print \$2}'", + // returnStdout: true + // ).trim() + // sh "echo Building project in version: $version" + // } + // } + // } - // stage('clean') { - // steps { - // sh "chmod +x gradlew" - // sh "./gradlew clean --no-daemon" - // } - // } + // stage('clean') { + // steps { + // sh "chmod +x gradlew" + // sh "./gradlew clean --no-daemon" + // } + // } - // stage('build') { - // steps { - // sh "./gradlew npm_install -Pprod -PnodeInstall --no-daemon" - // } - // } + // stage('build') { + // steps { + // sh "./gradlew npm_install -Pprod -PnodeInstall --no-daemon" + // } + // } - // stage('quality analysis') { - // steps { - // withSonarQubeEnv('sonarqube') { - // sh "./gradlew sonarqube --no-daemon -PnodeInstall -Pprod" - // } - // } - // } + // stage('quality analysis') { + // steps { + // withSonarQubeEnv('sonarqube') { + // sh "./gradlew sonarqube --no-daemon -PnodeInstall -Pprod" + // } + // } + // } - // stage('backend tests') { - // steps { - // script { - // try { - // sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" - // } catch(err) { - // throw err - // } finally { - // junit '**/build/**/TEST-*.xml' } - // } - // } - // } + // stage('backend tests') { + // steps { + // script { + // try { + // sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" + // } catch(err) { + // throw err + // } finally { + // junit '**/build/**/TEST-*.xml' } + // } + // } + // } - // stage('frontend tests') { - // steps { - // script { - // try { - // sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" - // } catch(err) { - // throw err - // } finally { - // junit '**/build/test-results/TESTS-*.xml' } - // } - // } - // } + // stage('frontend tests') { + // steps { + // script { + // try { + // sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" + // } catch(err) { + // throw err + // } finally { + // junit '**/build/test-results/TESTS-*.xml' } + // } + // } + // } - // stage('packaging') { - // steps { - // sh "./gradlew bootJar -x test -Pprod -PnodeInstall --no-daemon" - // archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true - // } - // } + // stage('packaging') { + // steps { + // sh "./gradlew bootJar -x test -Pprod -PnodeInstall --no-daemon" + // archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true + // } + // } - // stage ('Publish') { - // steps { - // nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] - // } - // } + // stage ('Publish') { + // steps { + // nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] + // } + // } stage('terraform init') { steps { @@ -114,30 +114,30 @@ pipeline { steps { dir('./terraform/prod'){ sh "echo 'Planning Terraform Build'" - sh "terraform plan"//-var 'access_key=${env.ACCESS_KEY}' -var 'secret_key=${env.SECRET_KEY}'" + sh "terraform plan" } } } - // stage('terraform apply'){ - // steps { - // script{ - // def apply = false - // try { - // input message: 'Can you please confirm the apply', ok: 'Ready to Apply the Config' - // apply = true - // } catch (err) { - // apply = false - // currentBuild.result = 'UNSTABLE' - // } - // if(apply){ - // dir('./terraform/prod'){ - // sh "echo 'Applying Terraform'" - // sh 'terraform apply --auto-approve' - // } - // } - // } - // } - // } + stage('terraform apply'){ + steps { + script{ + def apply = false + try { + input message: 'Can you please confirm the apply', ok: 'Ready to Apply the Config' + apply = true + } catch (err) { + apply = false + currentBuild.result = 'UNSTABLE' + } + if(apply){ + dir('./terraform/prod'){ + sh "echo 'Applying Terraform'" + sh 'terraform apply --auto-approve' + } + } + } + } + } } } diff --git a/terraform/prod/main.tf b/terraform/prod/main.tf index ca3527c..d96dfa1 100644 --- a/terraform/prod/main.tf +++ b/terraform/prod/main.tf @@ -5,7 +5,6 @@ terraform { region = "us-east-1" profile = "sts" } - # required_version = "0.11.10" } module "security_group" { source = "../modules/security_group" From 106486a3b573950c3375205b706102fa52252635 Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 15:20:45 -0400 Subject: [PATCH 17/29] uncommenting all steps --- Jenkinsfile.integration | 150 ++++++++++++++++++++-------------------- 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/Jenkinsfile.integration b/Jenkinsfile.integration index dfaa2fe..53921f2 100644 --- a/Jenkinsfile.integration +++ b/Jenkinsfile.integration @@ -14,91 +14,91 @@ pipeline { } stages{ - // stage('checkout') { - // steps { - // checkout scm - // echo "workspace directory is ${workspace}" - // } - // } + stage('checkout') { + steps { + checkout scm + echo "workspace directory is ${workspace}" + } + } - // stage('check java') { - // steps { - // sh "java -version" - // } - // } + stage('check java') { + steps { + sh "java -version" + } + } - // stage('get project version') { - // steps { - // script { - // version = sh ( - // script: "./gradlew properties -q | grep \"^version:\" | awk '{print \$2}'", - // returnStdout: true - // ).trim() - // sh "echo Building project in version: $version" - // } - // } - // } + stage('get project version') { + steps { + script { + version = sh ( + script: "./gradlew properties -q | grep \"^version:\" | awk '{print \$2}'", + returnStdout: true + ).trim() + sh "echo Building project in version: $version" + } + } + } - // stage('clean') { - // steps { - // sh "chmod +x gradlew" - // sh "./gradlew clean --no-daemon" - // } - // } + stage('clean') { + steps { + sh "chmod +x gradlew" + sh "./gradlew clean --no-daemon" + } + } - // stage('build') { - // steps { - // sh "./gradlew npm_install -Pprod -PnodeInstall --no-daemon" - // } - // } + stage('build') { + steps { + sh "./gradlew npm_install -Pprod -PnodeInstall --no-daemon" + } + } - // stage('quality analysis') { - // steps { - // withSonarQubeEnv('sonarqube') { - // sh "./gradlew sonarqube --no-daemon -PnodeInstall -Pprod" - // } - // } - // } + stage('quality analysis') { + steps { + withSonarQubeEnv('sonarqube') { + sh "./gradlew sonarqube --no-daemon -PnodeInstall -Pprod" + } + } + } - // stage('backend tests') { - // steps { - // script { - // try { - // sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" - // } catch(err) { - // throw err - // } finally { - // junit '**/build/**/TEST-*.xml' } - // } - // } - // } + stage('backend tests') { + steps { + script { + try { + sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" + } catch(err) { + throw err + } finally { + junit '**/build/**/TEST-*.xml' } + } + } + } - // stage('frontend tests') { - // steps { - // script { - // try { - // sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" - // } catch(err) { - // throw err - // } finally { - // junit '**/build/test-results/TESTS-*.xml' } - // } - // } - // } + stage('frontend tests') { + steps { + script { + try { + sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" + } catch(err) { + throw err + } finally { + junit '**/build/test-results/TESTS-*.xml' } + } + } + } - // stage('packaging') { - // steps { - // sh "./gradlew bootJar -x test -Pprod -PnodeInstall --no-daemon" - // archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true - // } - // } + stage('packaging') { + steps { + sh "./gradlew bootJar -x test -Pprod -PnodeInstall --no-daemon" + archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true + } + } - // stage ('Publish') { - // steps { - // nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] - // } - // } + stage ('Publish') { + steps { + nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] + } + } stage('terraform init') { steps { From d06db3cf622c7e81ba2afd63b1759c2e5570d3fb Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 25 Jun 2019 15:48:27 -0400 Subject: [PATCH 18/29] added terraform destroy pipeline --- Jenkinsfile.destroy | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Jenkinsfile.destroy diff --git a/Jenkinsfile.destroy b/Jenkinsfile.destroy new file mode 100644 index 0000000..70b78b8 --- /dev/null +++ b/Jenkinsfile.destroy @@ -0,0 +1,57 @@ + +//This pipeline should be run to destroy terraform resources +pipeline { + agent any + + tools { + "org.jenkinsci.plugins.terraform.TerraformInstallation" "terraform-0.11.10" + } + + environment { + TF_HOME = tool('terraform-0.11.10') + TF_IN_AUTOMATION = "true" + PATH = "$TF_HOME:$PATH" + ACCESS_KEY = credentials('jenkins-aws-secret-key-id') + SECRET_KEY = credentials('jenkins-aws-secret-access-key') + } + + stages{ + stage('checkout') { + steps { + checkout scm + echo "workspace directory is ${workspace}" + } + } + + stage('terraform init') { + steps { + dir('./terraform/prod'){ + sh "terraform --version" + sh "echo 'Initializing Terraform'" + sh "terraform init -input=false" + } + } + } + + stage('terraform apply'){ + steps { + script{ + def apply = false + try { + input message: 'Can you please confirm the destroy', ok: 'Ready to Destroy the Infrastructure' + apply = true + } catch (err) { + apply = false + currentBuild.result = 'UNSTABLE' + } + if(apply){ + dir('./terraform/prod'){ + sh "echo 'Applying Terraform'" + sh 'terraform destroy --auto-approve' + } + } + } + } + } + } +} From 231ca2e665017833cab6443b57daba82f9283edc Mon Sep 17 00:00:00 2001 From: Wes Date: Wed, 26 Jun 2019 08:47:02 -0400 Subject: [PATCH 19/29] updated main jenkinsfile, added public ip to tf --- Jenkinsfile | 143 ++++++++++++++++++++++++++++++++++ Jenkinsfile.destroy | 2 +- terraform/modules/ec2/main.tf | 2 + 3 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..53921f2 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,143 @@ +pipeline { + agent any + + tools { + "org.jenkinsci.plugins.terraform.TerraformInstallation" "terraform-0.11.10" + } + + environment { + TF_HOME = tool('terraform-0.11.10') + TF_IN_AUTOMATION = "true" + PATH = "$TF_HOME:$PATH" + ACCESS_KEY = credentials('jenkins-aws-secret-key-id') + SECRET_KEY = credentials('jenkins-aws-secret-access-key') + } + + stages{ + stage('checkout') { + steps { + checkout scm + echo "workspace directory is ${workspace}" + } + } + + stage('check java') { + steps { + sh "java -version" + } + } + + stage('get project version') { + steps { + script { + version = sh ( + script: "./gradlew properties -q | grep \"^version:\" | awk '{print \$2}'", + returnStdout: true + ).trim() + sh "echo Building project in version: $version" + } + } + } + + stage('clean') { + steps { + sh "chmod +x gradlew" + sh "./gradlew clean --no-daemon" + } + } + + stage('build') { + steps { + sh "./gradlew npm_install -Pprod -PnodeInstall --no-daemon" + } + } + + stage('quality analysis') { + steps { + withSonarQubeEnv('sonarqube') { + sh "./gradlew sonarqube --no-daemon -PnodeInstall -Pprod" + } + } + } + + stage('backend tests') { + steps { + script { + try { + sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon" + } catch(err) { + throw err + } finally { + junit '**/build/**/TEST-*.xml' } + } + } + } + + + stage('frontend tests') { + steps { + script { + try { + sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon" + } catch(err) { + throw err + } finally { + junit '**/build/test-results/TESTS-*.xml' } + } + } + } + + stage('packaging') { + steps { + sh "./gradlew bootJar -x test -Pprod -PnodeInstall --no-daemon" + archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true + } + } + + stage ('Publish') { + steps { + nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]] + } + } + + stage('terraform init') { + steps { + dir('./terraform/prod'){ + sh "terraform --version" + sh "echo 'Initializing Terraform'" + sh "terraform init -input=false" + } + } + } + + stage('terraform plan'){ + steps { + dir('./terraform/prod'){ + sh "echo 'Planning Terraform Build'" + sh "terraform plan" + } + } + } + + stage('terraform apply'){ + steps { + script{ + def apply = false + try { + input message: 'Can you please confirm the apply', ok: 'Ready to Apply the Config' + apply = true + } catch (err) { + apply = false + currentBuild.result = 'UNSTABLE' + } + if(apply){ + dir('./terraform/prod'){ + sh "echo 'Applying Terraform'" + sh 'terraform apply --auto-approve' + } + } + } + } + } + } +} diff --git a/Jenkinsfile.destroy b/Jenkinsfile.destroy index 70b78b8..0cc4237 100644 --- a/Jenkinsfile.destroy +++ b/Jenkinsfile.destroy @@ -33,7 +33,7 @@ pipeline { } } - stage('terraform apply'){ + stage('terraform destroy'){ steps { script{ def apply = false diff --git a/terraform/modules/ec2/main.tf b/terraform/modules/ec2/main.tf index 3f74603..d9d889c 100644 --- a/terraform/modules/ec2/main.tf +++ b/terraform/modules/ec2/main.tf @@ -56,6 +56,8 @@ resource "aws_instance" "server" { vpc_security_group_ids = ["${var.security_groups}"] subnet_id = "${var.subnet_id}" + associate_public_ip_address = "True" + # iam_instance_profile = "${var.role}" lifecycle { From 39d1c1394b4c3f93176663d9807b876f42fcf607 Mon Sep 17 00:00:00 2001 From: Wes Date: Wed, 26 Jun 2019 09:19:15 -0400 Subject: [PATCH 20/29] fixed bool format --- terraform/modules/ec2/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/modules/ec2/main.tf b/terraform/modules/ec2/main.tf index d9d889c..91f6c2f 100644 --- a/terraform/modules/ec2/main.tf +++ b/terraform/modules/ec2/main.tf @@ -56,7 +56,7 @@ resource "aws_instance" "server" { vpc_security_group_ids = ["${var.security_groups}"] subnet_id = "${var.subnet_id}" - associate_public_ip_address = "True" + associate_public_ip_address = True # iam_instance_profile = "${var.role}" From d6357b23099d4d770f9d36a2061d177f4ff5974f Mon Sep 17 00:00:00 2001 From: Wes Date: Wed, 26 Jun 2019 13:25:49 -0400 Subject: [PATCH 21/29] fixed bool for real --- terraform/modules/ec2/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/modules/ec2/main.tf b/terraform/modules/ec2/main.tf index 91f6c2f..1689a5d 100644 --- a/terraform/modules/ec2/main.tf +++ b/terraform/modules/ec2/main.tf @@ -56,7 +56,7 @@ resource "aws_instance" "server" { vpc_security_group_ids = ["${var.security_groups}"] subnet_id = "${var.subnet_id}" - associate_public_ip_address = True + associate_public_ip_address = true # iam_instance_profile = "${var.role}" From eb596dc50236ae00a1459f7c161df944ddb84562 Mon Sep 17 00:00:00 2001 From: CloudDevOpsEngineer Date: Wed, 26 Jun 2019 20:54:40 -0400 Subject: [PATCH 22/29] added role --- terraform/modules/ec2/main.tf | 2 +- terraform/modules/ec2/variables.tf | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/terraform/modules/ec2/main.tf b/terraform/modules/ec2/main.tf index 1689a5d..9be5a54 100644 --- a/terraform/modules/ec2/main.tf +++ b/terraform/modules/ec2/main.tf @@ -58,7 +58,7 @@ resource "aws_instance" "server" { associate_public_ip_address = true - # iam_instance_profile = "${var.role}" + iam_instance_profile = "${var.role}" lifecycle { # prevent rebuild if a newer ami is released diff --git a/terraform/modules/ec2/variables.tf b/terraform/modules/ec2/variables.tf index bc0d412..72ca835 100644 --- a/terraform/modules/ec2/variables.tf +++ b/terraform/modules/ec2/variables.tf @@ -17,9 +17,9 @@ variable "security_groups" { variable "subnet_id" { } -# variable "role" { - -# } +variable "role" { + default = "s3_access_for_ec2" +} variable "OSDiskSize" { default = "8" From 78afebadb9419fd5eba1d562072d8057ee5adac1 Mon Sep 17 00:00:00 2001 From: CloudDevOpsEngineer Date: Thu, 27 Jun 2019 22:28:35 -0400 Subject: [PATCH 23/29] changing vpc --- terraform/prod/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/prod/main.tf b/terraform/prod/main.tf index d96dfa1..debf9d5 100644 --- a/terraform/prod/main.tf +++ b/terraform/prod/main.tf @@ -14,7 +14,7 @@ module "security_group" { sg_name = "dev_security_group" sg_description = "Allows access to demo resources" - vpc_id = "vpc-0e3945d5888632944" + vpc_id = "vpc-55cb052f" http_cidr = ["0.0.0.0/0"] ssh_cidr = ["0.0.0.0/0"] @@ -30,5 +30,5 @@ module "ec2_server" { name = "dev_server" - key = "demo_pipeline" + key = "26jun2019" } \ No newline at end of file From 062c8e98859d02be31851fabd6bdcaf4ff318720 Mon Sep 17 00:00:00 2001 From: CloudDevOpsEngineer Date: Thu, 27 Jun 2019 22:29:36 -0400 Subject: [PATCH 24/29] commented out subnet --- terraform/prod/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/prod/main.tf b/terraform/prod/main.tf index debf9d5..9824306 100644 --- a/terraform/prod/main.tf +++ b/terraform/prod/main.tf @@ -26,7 +26,7 @@ module "ec2_server" { instance_type = "t3.medium" security_groups = "${module.security_group.id}" - subnet_id = "subnet-0a1f8963d08b10d8f" + # subnet_id = "subnet-0a1f8963d08b10d8f" name = "dev_server" From fa996615e6329c94c874050759612975d3ec7b73 Mon Sep 17 00:00:00 2001 From: CloudDevOpsEngineer Date: Fri, 28 Jun 2019 08:25:34 -0400 Subject: [PATCH 25/29] updated vpc, subnet, and other values --- terraform/modules/security_group/main.tf | 58 ++++++++++++++----- terraform/modules/security_group/variables.tf | 7 +-- terraform/prod/main.tf | 11 ++-- 3 files changed, 48 insertions(+), 28 deletions(-) diff --git a/terraform/modules/security_group/main.tf b/terraform/modules/security_group/main.tf index be675c9..af90d44 100644 --- a/terraform/modules/security_group/main.tf +++ b/terraform/modules/security_group/main.tf @@ -8,30 +8,56 @@ resource "aws_security_group" "security_group" { vpc_id = "${var.vpc_id}" ingress { - from_port = 443 - to_port = 443 - protocol = "tcp" - cidr_blocks = "${var.http_cidr}" + # TLS (change to whatever ports you need) + from_port = 443 + to_port = 443 + + protocol = "tcp" + # Please restrict your ingress to only necessary IPs and ports. + # Opening to 0.0.0.0/0 can lead to security vulnerabilities. + cidr_blocks = ["0.0.0.0/0"] } + ingress { - from_port = 80 - to_port = 80 - protocol = "tcp" - cidr_blocks = "${var.http_cidr}" + # TLS (change to whatever ports you need) + from_port = 80 + to_port = 80 + + protocol = "tcp" + # Please restrict your ingress to only necessary IPs and ports. + # Opening to 0.0.0.0/0 can lead to security vulnerabilities. + cidr_blocks = ["0.0.0.0/0"] } + ingress { - from_port = 22 - to_port = 22 - protocol = "tcp" - cidr_blocks = "${var.ssh_cidr}" + # TLS (change to whatever ports you need) + from_port = 8080 + to_port = 8080 + + protocol = "tcp" + # Please restrict your ingress to only necessary IPs and ports. + # Opening to 0.0.0.0/0 can lead to security vulnerabilities. + cidr_blocks = ["0.0.0.0/0"] } + ingress { + # TLS (change to whatever ports you need) + from_port = 22 + to_port = 22 + + protocol = "tcp" + # Please restrict your ingress to only necessary IPs and ports. + # Opening to 0.0.0.0/0 can lead to security vulnerabilities. + cidr_blocks = ["0.0.0.0/0"] + } + egress { - from_port = 0 - to_port = 0 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] } + tags = { Name = "${var.sg_name}" } diff --git a/terraform/modules/security_group/variables.tf b/terraform/modules/security_group/variables.tf index b7350c2..7f2d4b8 100644 --- a/terraform/modules/security_group/variables.tf +++ b/terraform/modules/security_group/variables.tf @@ -13,9 +13,4 @@ variable "sg_description" { variable "vpc_id" { } -variable "http_cidr" { - type = "list" -} -variable "ssh_cidr" { - type = "list" -} + diff --git a/terraform/prod/main.tf b/terraform/prod/main.tf index 9824306..5beb410 100644 --- a/terraform/prod/main.tf +++ b/terraform/prod/main.tf @@ -14,21 +14,20 @@ module "security_group" { sg_name = "dev_security_group" sg_description = "Allows access to demo resources" - vpc_id = "vpc-55cb052f" + vpc_id = "vpc-0e3945d5888632944" + - http_cidr = ["0.0.0.0/0"] - ssh_cidr = ["0.0.0.0/0"] } module "ec2_server" { source = "../modules/ec2" profile = "sts" - instance_type = "t3.medium" + instance_type = "t2.micro" security_groups = "${module.security_group.id}" - # subnet_id = "subnet-0a1f8963d08b10d8f" + subnet_id = "subnet-02ccc03ce0ce2a594" name = "dev_server" - key = "26jun2019" + key = "demo_pipeline" } \ No newline at end of file From 0c9d83289910b75e736e3e6c0f5efa89cf0fb5fa Mon Sep 17 00:00:00 2001 From: CloudDevOpsEngineer Date: Fri, 28 Jun 2019 08:48:07 -0400 Subject: [PATCH 26/29] add first run list --- terraform/modules/ec2/main.tf | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/terraform/modules/ec2/main.tf b/terraform/modules/ec2/main.tf index 9be5a54..f560cbe 100644 --- a/terraform/modules/ec2/main.tf +++ b/terraform/modules/ec2/main.tf @@ -28,7 +28,11 @@ data "template_file" "init" { /bin/echo -e "validation_key \"/etc/chef/simpletechnologysolutions-validator.pem\"" >> /etc/chef/client.rb /bin/echo -e "chef_license \"accept\"" >> /etc/chef/client.rb - sudo chef-client + /bin/echo 'log_location STDOUT' >> /etc/chef/file.json + /bin/echo -e "{\"run_list\": [ \"role[release]\" ]}" + + sudo chef-client -j /etc/chef/file.json --environment _default + EOF } From 02b4a512f0ab98f8d73de5cc0e05acb3fe804353 Mon Sep 17 00:00:00 2001 From: CloudDevOpsEngineer Date: Fri, 28 Jun 2019 09:18:31 -0400 Subject: [PATCH 27/29] updated runlist --- terraform/modules/ec2/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/modules/ec2/main.tf b/terraform/modules/ec2/main.tf index f560cbe..0ed4930 100644 --- a/terraform/modules/ec2/main.tf +++ b/terraform/modules/ec2/main.tf @@ -29,7 +29,7 @@ data "template_file" "init" { /bin/echo -e "chef_license \"accept\"" >> /etc/chef/client.rb /bin/echo 'log_location STDOUT' >> /etc/chef/file.json - /bin/echo -e "{\"run_list\": [ \"role[release]\" ]}" + /bin/echo -e "{\\\"run_list\\\": [ \\\"role[release]\\\" ]}" sudo chef-client -j /etc/chef/file.json --environment _default From 21dc26d727392f2504c85e921eaa30e0ca661577 Mon Sep 17 00:00:00 2001 From: William Dealey Date: Fri, 28 Jun 2019 09:47:36 -0400 Subject: [PATCH 28/29] test --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 01785e4..1f7ab79 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # devopsdemo -#Test This application was generated using JHipster 6.0.1, you can find documentation and help at [https://www.jhipster.tech/documentation-archive/v6.0.1](https://www.jhipster.tech/documentation-archive/v6.0.1). From 4c6f5cd31eff8c25ae8beeb3d116f92778ae3c8d Mon Sep 17 00:00:00 2001 From: Wes Date: Fri, 28 Jun 2019 23:17:11 -0400 Subject: [PATCH 29/29] added destroy before build --- Jenkinsfile | 10 ++++++++++ Jenkinsfile.integration | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 53921f2..586247b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,6 +21,16 @@ pipeline { } } + stage('terraform destroy') { + steps { + dir('./terraform/prod'){ + sh "terraform --version" + sh "echo 'Destroying old Infrastructure'" + sh "terraform destroy --auto-approve" + } + } + } + stage('check java') { steps { sh "java -version" diff --git a/Jenkinsfile.integration b/Jenkinsfile.integration index 41100a4..985891b 100644 --- a/Jenkinsfile.integration +++ b/Jenkinsfile.integration @@ -21,6 +21,16 @@ pipeline { } } + stage('terraform destroy') { + steps { + dir('./terraform/prod'){ + sh "terraform --version" + sh "echo 'Destroying old Infrastructure'" + sh "terraform destroy --auto-approve" + } + } + } + stage('check java') { steps { sh "java -version"