Advertisement
Javi

cicd: simple jenkins conditional pipeline on aws

Sep 14th, 2021
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. def awsCredentials = [[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'aws-deploy-credentials']]
  2.  
  3. pipeline {
  4. agent any
  5.  
  6. environment {
  7. AWS_DEFAULT_REGION = 'eu-west-1'
  8. }
  9.  
  10. options {
  11. disableConcurrentBuilds()
  12. parallelsAlwaysFailFast()
  13. timestamps()
  14. withCredentials(awsCredentials)
  15. }
  16.  
  17. stages {
  18.  
  19. stage('build') {
  20. steps {
  21. sh """
  22. # Some commands
  23. echo Starting deployment.
  24. aws sts get-caller-identity
  25. """
  26. script {
  27. timeout(time: 10, unit: 'MINUTES') {
  28. finalStage = input message: 'What should I do next?', ok: 'Continue',
  29. parameters: [choice(name: 'Next stage:', choices: 'finish\nrollback\nlol', description: 'Finish will delete old version, rollback will activate the old version, abort will stop the pipeline.')]
  30. }
  31. }
  32. }
  33. }
  34.  
  35. stage('finish') {
  36. when {
  37. expression { finalStage == 'finish' }
  38. }
  39. steps {
  40. sh """
  41. # some commands
  42. echo "Good! Deleting green (old) version."
  43. """
  44. }
  45. }
  46. stage('rollback') {
  47. when {
  48. expression { finalStage == 'rollback' }
  49. }
  50. steps {
  51. sh """
  52. # some commands
  53. echo "No problem! Rolling back to green (old) version."
  54. """
  55. }
  56. }
  57. }
  58.  
  59. post {
  60. always {
  61. cleanWs()
  62. }
  63. }
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement