0
votes

I'm using Jenkins with CloudFormation and CodeDeploy plugin.

I am able to use jenkins to build CloudFormation stack when there is new commit to my git repo.

I'm able to deploy code to my EC2 instances in auto scaling group via CodeDeploy plugin as well.

Question:

How can I automate the entire process so that when my Jenkins job to create CloudFormation Stack is completed the CodeDeploy job can be triggered next to complete the code deployment process.

Cheers

2

2 Answers

1
votes

you could put both of these in one job. here it is in a declarative pipeline in two stages:

pipeline {
  agent { label 'docker' }
  stages {
    stage('cloudformation') {
      steps {
        sh './do_cloudformation.sh'
      }
    }
    stage('codedeploy') {
      steps {
        sh './do_codedeploy.sh'
      }
    }
  }
}

if you want to be able to trigger them independently, you could keep them in two jobs, but have the cloudformation job trigger the codedeploy job, by using the build step, like this:

pipeline {
  agent { label 'docker' }
  stages {
    stage('cloudformation') {
      steps {
        sh './do_cloudformation.sh'
      }
    }
    stage('codedeploy') {
      steps {
        build 'name-of-codedeploy-job'
      }
    }
  }
}
0
votes

Resolved the issue by selecting 'Build Triggers' with 'Build after other projects are built' option