Created
January 3, 2019 06:04
-
-
Save goforgold/dccf51355fb0e7539a76c443751a1222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipeline { | |
agent { | |
docker { | |
image 'goforgold/build-container:latest' | |
} | |
} | |
stages { | |
stage('Build') { | |
steps { | |
sh 'npm install' | |
} | |
} | |
stage('Create Packer AMI') { | |
steps { | |
withCredentials([ | |
usernamePassword(credentialsId: 'ada90a34-30ef-47fb-8a7f-a97fe69ff93f', passwordVariable: 'AWS_SECRET', usernameVariable: 'AWS_KEY') | |
]) { | |
sh 'packer build -var aws_access_key=${AWS_KEY} -var aws_secret_key=${AWS_SECRET} packer/packer.json' | |
} | |
} | |
} | |
stage('AWS Deployment') { | |
steps { | |
withCredentials([ | |
usernamePassword(credentialsId: 'ada90a34-30ef-47fb-8a7f-a97fe69ff93f', passwordVariable: 'AWS_SECRET', usernameVariable: 'AWS_KEY'), | |
usernamePassword(credentialsId: '2facaea2-613b-4f34-9fb7-1dc2daf25c45', passwordVariable: 'REPO_PASS', usernameVariable: 'REPO_USER'), | |
]) { | |
sh 'rm -rf node-app-terraform' | |
sh 'git clone https://github.com/goforgold/node-app-terraform.git' | |
sh ''' | |
cd node-app-terraform | |
terraform init | |
terraform apply -auto-approve -var access_key=${AWS_KEY} -var secret_key=${AWS_SECRET} | |
git add terraform.tfstate | |
git -c user.name="Shashwat Tripathi" -c user.email="[email protected]" commit -m "terraform state update from Jenkins" | |
git push https://${REPO_USER}:${REPO_PASS}@github.com/goforgold/node-app-terraform.git master | |
''' | |
} | |
} | |
} | |
} | |
environment { | |
npm_config_cache = 'npm-cache' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment