Guest User

Untitled

a guest
May 24th, 2018
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #!groovy
  2.  
  3. node {
  4.  
  5. def err = null
  6. def environment = "Development"
  7. currentBuild.result = "SUCCESS"
  8.  
  9. try {
  10. stage ('Checkout') {
  11. checkout scm
  12. }
  13.  
  14. /* Show Version so we know if we need to update or not */
  15. stage ('Version') {
  16. sh """
  17. set +x
  18. packer version
  19. """
  20. }
  21.  
  22. /* If Validation fails, Pipeline fails. See Console for errors */
  23. stage ('Validate') {
  24. sh """
  25. set +x
  26. packer validate dcos_agent_centos7.4.json
  27. """
  28. }
  29.  
  30. /* Build if validation passes */
  31. stage ('Build') {
  32. withCredentials([string(credentialsId: 'aws-access-key', variable: 'AWS_ACCESS_KEY_ID'),
  33. string(credentialsId: 'aws-secret-key', variable: 'AWS_SECRET_ACCESS_KEY')]) {
  34. sh """
  35. set +x
  36. packer build -var aws_access_key=${AWS_ACCESS_KEY_ID} -var aws_secret_key=${AWS_SECRET_ACCESS_KEY} dcos_agent_centos7.4.json
  37. """
  38. }
  39. }
  40.  
  41. stage ('Notify') {
  42. mail from: "email@email.com",
  43. to: "email@email.com",
  44. subject: "Packer Build for ${environment} Complete.",
  45. body: "Jenkins Job ${env.JOB_NAME} - build ${env.BUILD_NUMBER} for ${environment}. Please investigate."
  46. }
  47. }
  48.  
  49. catch (caughtError) {
  50. err = caughtError
  51. currentBuild.result = "FAILURE"
  52. }
  53.  
  54. finally {
  55. /* Must re-throw exception to propagate error */
  56. if (err) {
  57. throw err
  58. }
  59. }
  60. }
Add Comment
Please, Sign In to add comment