Yeah - I know Jake was looking into something similar for us. I have a deployment pipeline for handling rainbow deployments that I use for a number of different stacks - but the stacks all take different build variables so there was no practical way to have the pipeline trigger the stack build without creating a separate pipeline for every stack individually (which I did not want to do).
For now (unless and until Jake figures out a way to simplify) I have my CI/CD process push the stack build via the API (so that each project could specify the appropriate variables for its build) and then using a single pipeline that takes the build id from the API call and triggers off the rest of the release process. Deployment script looks like this:
#!/bin/bash
HEADERS=(
-H "X-Hub-Id: $CYCLE_HUB_ID" \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $CYCLE_API_TOKEN" \
)
# Create the new build and capture the response
response=$(curl --location "https://api.cycle.io/v1/stacks/$CYCLE_STACK_ID/builds" \
-s "${HEADERS[@]}" \
-d '{
"about": {
"version": "'"$SERVICE_NAME-$IMAGE_TAG"'",
"description": "'"$SERVICE_NAME deployment of image $IMAGE_TAG"'"
},
"instructions": {
"git": {
"type": "branch",
"value": "'"$BITBUCKET_BRANCH"'"
},
"variables": {
"source": "'"$CYCLE_SOURCE_ID"'",
"target": "busify-'"$SERVICE_NAME:$IMAGE_TAG"'",
"db-user": "'"$DB_USER"'",
"db-pass": "'"$DB_PASS"'",
"new-relic-license-key": "'"$NEW_RELIC_LICENSE_KEY"'",
"amqp-user": "'"$AMQP_USER"'",
"amqp-pass": "'"$AMQP_PASS"'"
}
}
}')
# Extract the build ID from the response using jq
build_id=$(echo "$response" | jq -r '.data.id')
# Check if build_id is empty or null
if [ -z "$build_id" ] || [ "$build_id" == "null" ]; then
echo "Failed to extract build ID from the response"
exit 1
fi
echo "Extracted build ID: $build_id"
# Trigger the pipeline with the extracted build ID
curl -v -k "https://api.cycle.io/v1/pipelines/$CYCLE_RAINBOW_PIPELINE_ID/tasks" \
-s "${HEADERS[@]}" \
-d '{
"action": "trigger",
"contents": {
"variables": {
"build": "'"$build_id"'",
"environment": "'"$CYCLE_ENVIRONMENT_ID"'",
"service": "'"$SERVICE_NAME"'",
"tag": "'"$IMAGE_TAG"'"
}
}
}'