Injecting a prebaked AMI (and other parameters) into a Spinnaker Pipeline

Aug 22, 2016 by Isaac Mosquera

While Spinnaker has a preferred way of doing things it’s also highly customizable. The easiest way to use Spinnaker is to have it bake your pipeline using Rosco + Packer and pass it along to the next deployment stage. Below is a fairly standard way of using Spinnaker.

But what if your AMI is baked as part of the continuous integration server like TravisCI, CircleCI and not Jenkins? In order for Spinnaker to work well with this model we’ll have to do a few things:

  1. Create a custom parameter that is used to specify the AMI that was created during CI process that will be used within the deployment process. Make sure that your deployment account has access to the AMI.
  2. Use Spinnaker’s pipeline expressions that allow you to access parameters & properties that were created or passed in during run process. This allows stages to pass along values to next stages. We’ll have to modify the pipeline JSON to accept a custom value that we pass when the pipeline is kicked off.
  3. Kick-off the pipeline once the external CI service’s job is complete. The CI service should run unit tests, build & create AMI and then publish the AMI to an account accessible by Spinnaker.

Create A Custom Trigger Parameter

We’ll start by creating a parameter that is used at the beginning of the pipeline. Make sure to go back to your Configuration stage, which is the first one in the pipeline.

Then add a parameter with whatever value you want to use downstream. For our use-case we want to build a pre-baked AMI so we’ll change that here. We’ve added the name prebaked_ami with a default value: ami-0123456789 that we’ll get to use in later stages with the pipelines expressions feature by referring to this variable ${trigger.parameters.prebaked_ami}.

Use Pipeline Expressions

The next step is use the pipeline expressions feature to modify the pipeline by exposing the pipeline JSON and manually modifying it. If manually modifying the JSON scares you a bit, that’s okay. You can always store the final JSON in a SCM like git and post the JSON to Spinnaker’s robust API to manage the pipeline.

Once you have access to the JSON we’ll want to add expression parameter that we prepared earlier: ${trigger.parameters.prebaked_ami} to the clusters array in the JSON. This will tell the pipeline to use the value that we’ll pass in in the next step.

Note: You’ll see a little warning symbol on top of the pipeline saying that you need a bake step. You can safely ignore this warning as we added the amiName field to the JSON.

Kick-off The Pipeline

The last step is the easiest which is calling the Spinnaker API to kick-off the appropriate pipeline with the parameter(s) that are required as input. Spinnaker is 100% API based and all UI functionality is accessible through an API. If you’re interested in learning more about Spinnaker’s API you can always go to your instance’s swagger interface:

Below is the simple curl command that will trigger the pipeline

curl \
'http://${YOURINSTANCE}:8084/pipelines/${app_name}/${pipeline_name' \
-H 'Content-Type: application/json;charset=UTF-8' \
--data-binary '{"type":"manual","parameters":{"prebaked_ami":"${baked_ami_id}","user":"[anonymous]"}'

Recently Published Posts

Spinnaker tips: Integration of Terraform & Kubernetes in a pipeline

Dec 8, 2023

Spinnaker is an incredibly powerful platform that lets you deploy to multiple locations and targets concurrently. An example of this includes armory plugin which lets you call terraform and capture the output of terraform commands (this is similar to how you can capture logs from RunJobs but our integration is a deeper integration and […]

Read more

Spinnaker Tips: Setting a github status check on a PR from a pipeline

Oct 12, 2023

A common situation we hit is creating a pull request on github with some terraform changes that are run through our pipelines. We’d like to verify the terraform changes cleanly “plan” before we apply them. An example is when someone has a typo (how many times I’ve left dangling commas in a JSON object!) and […]

Read more

Introducing Pipelines-as-Code Plugin for Open Source Spinnaker

Jul 21, 2023

Easily Scale and Automate with Version Control in Git Developers choose best-of-breed version control systems like GitHub for a reason: they need the ability to collaborate and improve code together.  But a broken Spinnaker deployment pipeline can often be the last thing standing in the way of getting your application to market.  Until now. Armory‚Äôs […]

Read more