Skip to main content

Jenkins

Integrate Cloud Cost Analyzer into your Jenkins pipelines.

The cleanest Jenkins integration is the CCA Shared Library. It installs the binary (cached per workspace), runs the scan, archives results, and optionally fails the build on critical findings, from a single step:

@Library('cca') _

pipeline {
agent any
environment {
AWS_ACCESS_KEY_ID = credentials('aws-access-key')
AWS_SECRET_ACCESS_KEY = credentials('aws-secret-key')
CCA_API_KEY = credentials('cca-api-key')
}
stages {
stage('Cost Analysis') {
steps {
costAnalysis(provider: 'aws', mode: 'managed', failOnCritical: true)
}
}
}
}

Configure the library once under Manage Jenkins > System > Global Pipeline Libraries (point it at the SCM repo hosting the CCA vars/ directory). It requires the Pipeline Utility Steps plugin (readJSON). costAnalysis(...) returns the parsed scan result for further steps.

ParamDefaultDescription
providerawsaws or azure
regions(all default)Comma-separated regions
modemanagedScan mode (managed needs CCA_API_KEY)
failOnCriticalfalseFail the build on any Critical finding
ccaVersionlatestReleased version to download

The Jenkinsfile examples below wire the binary manually if you prefer not to install a shared library.

Quick Start (manual setup)

Add a cost analysis stage to your Jenkinsfile:

// Jenkinsfile
pipeline {
agent any

environment {
AWS_ACCESS_KEY_ID = credentials('aws-access-key')
AWS_SECRET_ACCESS_KEY = credentials('aws-secret-key')
AWS_REGION = 'us-east-1'
CCA_API_KEY = credentials('cca-api-key')
}

stages {
stage('Install CCA') {
steps {
sh '''
curl -LO https://releases.dragonfractal.com/cca/latest/cca-linux-amd64.tar.gz
tar -xzf cca-linux-amd64.tar.gz
chmod +x cca
'''
}
}

stage('Cost Analysis') {
steps {
sh './cca scan --provider aws --mode managed --output json > results.json'
}
}

stage('Archive Results') {
steps {
archiveArtifacts artifacts: 'results.json'
}
}
}
}

Configuration

Credentials

Add credentials in Manage Jenkins > Manage Credentials:

IDTypeDescription
aws-access-keySecret textAWS access key ID
aws-secret-keySecret textAWS secret access key
cca-api-keySecret textCCA API key for managed mode

For Azure:

IDTypeDescription
azure-client-idSecret textService principal client ID
azure-client-secretSecret textService principal secret
azure-tenant-idSecret textAzure AD tenant ID
azure-subscription-idSecret textSubscription to scan

Use Cases

Scheduled Analysis

Create a scheduled job for regular cost analysis:

// Jenkinsfile
pipeline {
agent any

triggers {
// Run every Monday at 9 AM
cron('0 9 * * 1')
}

environment {
AWS_ACCESS_KEY_ID = credentials('aws-access-key')
AWS_SECRET_ACCESS_KEY = credentials('aws-secret-key')
AWS_REGION = 'us-east-1'
CCA_API_KEY = credentials('cca-api-key')
}

stages {
stage('Setup') {
steps {
sh '''
curl -LO https://releases.dragonfractal.com/cca/latest/cca-linux-amd64.tar.gz
tar -xzf cca-linux-amd64.tar.gz
chmod +x cca
'''
}
}

stage('AWS Analysis') {
steps {
sh './cca scan --provider aws --mode managed'
}
}
}

post {
always {
// Send notification
emailext (
subject: "Cost Analysis Report - Build ${BUILD_NUMBER}",
body: "Weekly cost analysis complete. View results at: ${BUILD_URL}",
recipientProviders: [developers()]
)
}
}
}

Multi-Region Scan

Scan multiple AWS regions in parallel:

// Jenkinsfile
pipeline {
agent any

environment {
AWS_ACCESS_KEY_ID = credentials('aws-access-key')
AWS_SECRET_ACCESS_KEY = credentials('aws-secret-key')
CCA_API_KEY = credentials('cca-api-key')
}

stages {
stage('Setup') {
steps {
sh '''
curl -LO https://releases.dragonfractal.com/cca/latest/cca-linux-amd64.tar.gz
tar -xzf cca-linux-amd64.tar.gz
chmod +x cca
'''
}
}

stage('Scan Regions') {
parallel {
stage('us-east-1') {
steps {
sh './cca scan --provider aws --regions us-east-1 --mode managed'
}
}
stage('us-west-2') {
steps {
sh './cca scan --provider aws --regions us-west-2 --mode managed'
}
}
stage('eu-west-1') {
steps {
sh './cca scan --provider aws --regions eu-west-1 --mode managed'
}
}
}
}
}
}

Compliance Gate

Fail the build on critical findings:

// Jenkinsfile
pipeline {
agent any

environment {
AWS_ACCESS_KEY_ID = credentials('aws-access-key')
AWS_SECRET_ACCESS_KEY = credentials('aws-secret-key')
AWS_REGION = 'us-east-1'
}

stages {
stage('Setup') {
steps {
sh '''
curl -LO https://releases.dragonfractal.com/cca/latest/cca-linux-amd64.tar.gz
tar -xzf cca-linux-amd64.tar.gz
chmod +x cca
'''
}
}

stage('Cost Analysis') {
steps {
sh './cca scan --provider aws --output json > results.json'
}
}

stage('Compliance Check') {
steps {
script {
def results = readJSON file: 'results.json'
def criticalCount = results.findings.count { it.severity == 'Critical' }
def highCount = results.findings.count { it.severity == 'High' }

echo "Critical findings: ${criticalCount}"
echo "High findings: ${highCount}"
echo "Total monthly savings: \$${results.summary.total_monthly_savings}"

if (criticalCount > 0) {
error "Build failed: ${criticalCount} critical cost findings detected!"
}
}
}
}
}

post {
always {
archiveArtifacts artifacts: 'results.json'
}
}
}

Multi-Cloud Pipeline

Scan both AWS and Azure:

// Jenkinsfile
pipeline {
agent any

environment {
CCA_API_KEY = credentials('cca-api-key')
}

stages {
stage('Setup') {
steps {
sh '''
curl -LO https://releases.dragonfractal.com/cca/latest/cca-linux-amd64.tar.gz
tar -xzf cca-linux-amd64.tar.gz
chmod +x cca
'''
}
}

stage('Cloud Analysis') {
parallel {
stage('AWS') {
environment {
AWS_ACCESS_KEY_ID = credentials('aws-access-key')
AWS_SECRET_ACCESS_KEY = credentials('aws-secret-key')
AWS_REGION = 'us-east-1'
}
steps {
sh './cca scan --provider aws --mode managed'
}
}
stage('Azure') {
environment {
AZURE_CLIENT_ID = credentials('azure-client-id')
AZURE_CLIENT_SECRET = credentials('azure-client-secret')
AZURE_TENANT_ID = credentials('azure-tenant-id')
AZURE_SUBSCRIPTION_ID = credentials('azure-subscription-id')
}
steps {
sh './cca scan --provider azure --mode managed'
}
}
}
}
}
}

Generate HTML Report

Generate and publish an HTML report:

// Jenkinsfile
pipeline {
agent any

environment {
AWS_ACCESS_KEY_ID = credentials('aws-access-key')
AWS_SECRET_ACCESS_KEY = credentials('aws-secret-key')
AWS_REGION = 'us-east-1'
}

stages {
stage('Setup') {
steps {
sh '''
curl -LO https://releases.dragonfractal.com/cca/latest/cca-linux-amd64.tar.gz
tar -xzf cca-linux-amd64.tar.gz
chmod +x cca
'''
}
}

stage('Cost Analysis') {
steps {
sh './cca scan --provider aws --output markdown --output-file cost-report.md'
}
}
}

post {
always {
publishHTML(target: [
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: '.',
reportFiles: 'cost-report.html',
reportName: 'Cost Analysis Report'
])
}
}
}

Docker Agent

Run in a Docker container:

// Jenkinsfile
pipeline {
agent {
docker {
image 'dragonfractal/cca:latest'
}
}

environment {
AWS_ACCESS_KEY_ID = credentials('aws-access-key')
AWS_SECRET_ACCESS_KEY = credentials('aws-secret-key')
AWS_REGION = 'us-east-1'
CCA_API_KEY = credentials('cca-api-key')
}

stages {
stage('Cost Analysis') {
steps {
sh 'cca scan --provider aws --mode managed'
}
}
}
}

Shared Library

Create a shared library for reuse across projects:

// vars/costAnalysis.groovy
def call(Map config = [:]) {
def provider = config.provider ?: 'aws'
def region = config.region ?: 'us-east-1'
def managed = config.managed ?: true

sh '''
if [ ! -f cca ]; then
curl -LO https://releases.dragonfractal.com/cca/latest/cca-linux-amd64.tar.gz
tar -xzf cca-linux-amd64.tar.gz
chmod +x cca
fi
'''

def modeFlag = managed ? '--mode managed' : ''
sh "./cca scan --provider ${provider} --regions ${region} ${modeFlag}"
}

Usage in Jenkinsfile:

@Library('my-shared-lib') _

pipeline {
agent any

environment {
AWS_ACCESS_KEY_ID = credentials('aws-access-key')
AWS_SECRET_ACCESS_KEY = credentials('aws-secret-key')
CCA_API_KEY = credentials('cca-api-key')
}

stages {
stage('Cost Analysis') {
steps {
costAnalysis(provider: 'aws', region: 'us-east-1', managed: true)
}
}
}
}

Next Steps