Deploy CloudFormation ChangeSets with Jenkins Pipelines

AWS changesets allows the preview of proposed changes of cloudformations stack and how the changes will impact the resources in the stack, weather critical resources will be replaced or deleted.

2 new ciinabox-pipeline methods have been created to allow the use of changesets within a jenkins pipeline. createChangeSet() method creates the changeset with a generated id and displays the proposed changes and executeChangeSet() executes those changes.

This example creates a changeset from a cloudformation template in s3, waits for approval via an input step and then once approved executes the changes and waits for the execution to complete.

stage('deploy changeset to dev stack') {
  environment {
    STACK_NAME = 'demo-changeset-dev'
    ENVIRONMET_NAME = 'dev'
    TEMPLATE_URL = 'https://s3-ap-southeast-2.amazonaws.com/base2.demos/changeset/0.1.0/template.yaml'
    AWS_REGION = 'ap-southeast-2'
  }
  steps {
    createChangeSet(
      description: env.GIT_COMMIT,
      region: env.AWS_REGION,
      stackName: env.STACK_NAME,
      templateUrl: env.TEMPLATE_URL,
      parameters: [
        'EnvironmentName': env.ENVIRONMET_NAME,
        'Test': 'test'
      ]
    )

    input(
      message: "Execute changes ${env.DEMO_CHANGESET_DEV_CHANGESET_NAME}"
    )

    executeChangeSet(
      region: env.AWS_REGION,
      stackName: env.STACK_NAME
    )
  }
}