circle_ci plugin
Getting Started
This project is a fastlane plugin. To get started with fastlane-plugin-circle_ci
, add it to your project by running:
fastlane add_plugin circle_ci
About circle_ci
A fastlane plugin for Circle CI. 🚀
This plugin provides a set of actions that allow you to interact with CircleCI from your fastlane workflows. It supports both CircleCI API v1.1 (legacy) and API v2 (current).
Contributors
The actions in this plugin were created and enhanced with the assistance of GitHub Copilot, working alongside human developers to provide a comprehensive set of CircleCI integrations for your fastlane workflows.
Available Actions
CircleCI API v2 Actions
Pipeline Management
-
circleci_trigger_pipeline
: Triggers a new CircleCI pipeline -
circleci_get_pipeline
: Gets details of a specific pipeline -
circleci_get_pipeline_workflows
: Gets workflows for a pipeline -
circleci_wait_for_pipeline
: Waits for a pipeline to complete -
circleci_continue_pipeline
: Continues a pipeline that is on hold -
circleci_get_pipeline_by_number
: Gets a pipeline by its number -
circleci_get_pipeline_config
: Gets the configuration of a pipeline -
circleci_get_my_pipelines
: Gets pipelines associated with the current user -
circleci_get_pipeline_values
: Gets pipeline parameter values
Workflow and Job Management
-
circleci_get_workflow_jobs
: Gets jobs for a workflow -
circleci_get_job_details
: Gets detailed information about a job -
circleci_get_job_artifacts
: Gets artifacts generated by a job -
circleci_download_artifact
: Downloads an artifact to a local path -
circleci_download_workflow_artifacts
: Downloads all artifacts from a specific workflow -
circleci_approve_job
: Approves a pending approval job in a workflow -
circleci_cancel_job
: Cancels a running job -
circleci_cancel_workflow
: Cancels a running workflow -
circleci_get_job_tests
: Gets test metadata for a job -
circleci_get_job_timeseries
: Gets timeseries data for a job
Environment Variable Management
-
circleci_get_env_vars
: Gets environment variables for a project -
circleci_set_env_var
: Sets an environment variable for a project -
circleci_delete_env_var
: Deletes an environment variable from a project
Context Management
-
circleci_list_contexts
: Lists available contexts for an owner -
circleci_get_context_env_vars
: Gets environment variables for a context -
circleci_add_context_env_var
: Adds an environment variable to a context -
circleci_delete_context_env_var
: Deletes an environment variable from a context
Project Management
-
circleci_add_project_collaborator
: Adds a collaborator to a project -
circleci_create_project
: Creates a new CircleCI project -
circleci_get_project_branches
: Gets all branches for a project -
circleci_get_project_config
: Gets the configuration of a project -
circleci_get_project_workflow_metrics
: Gets workflow metrics for a project
Schedule Management
-
circleci_create_pipeline_schedule
: Creates a pipeline schedule -
circleci_list_pipeline_schedules
: Lists all pipeline schedules for a project -
circleci_delete_pipeline_schedule
: Deletes a pipeline schedule
Webhook Management
-
circleci_create_webhook
: Creates a webhook for a project -
circleci_delete_webhook
: Deletes a webhook
Pipeline Definition Management
-
circleci_create_pipeline_definition
: Creates a pipeline definition -
circleci_get_pipeline_definition
: Gets details of a pipeline definition -
circleci_get_pipeline_definitions
: Lists all pipeline definitions -
circleci_delete_pipeline_definition
: Deletes a pipeline definition -
circleci_create_pipeline_definition_trigger
: Creates a pipeline definition trigger -
circleci_delete_trigger
: Deletes a pipeline trigger -
circleci_get_trigger
: Gets information about a pipeline trigger
Checkout Key Management
-
circleci_create_checkout_key
: Creates a checkout key for a project -
circleci_get_checkout_key
: Gets details of a specific checkout key -
circleci_get_checkout_keys
: Lists all checkout keys for a project -
circleci_delete_checkout_key
: Deletes a checkout key
Analytics and Insights
-
circleci_get_flaky_tests
: Gets flaky tests information for a project -
circleci_get_workflow_insights
: Gets insights data for a workflow -
circleci_get_workflow_job_metrics
: Gets metrics for jobs in a workflow -
circleci_get_workflow_runs
: Gets recent runs of a workflow -
circleci_get_workflow_summary
: Gets summary metrics for a workflow -
circleci_get_org_summary
: Gets summary metrics for an organization -
circleci_get_user_info
: Gets information about the authenticated user
Legacy API v1.1 Actions
-
trigger_circle_ci_job
: Triggers a specific job in CircleCI -
get_circle_ci_build_status
: Gets the status of a CircleCI build -
get_circle_ci_artifacts
: Gets artifacts from a CircleCI build -
download_circle_ci_artifact
: Downloads a CircleCI artifact
Example
Triggering a Pipeline and Waiting for Completion
# Trigger a pipeline on the main branch
pipeline = circleci_trigger_pipeline(
project_slug: "github/myorg/myrepo",
branch: "main",
parameters: {
"deploy_env" => "staging",
"run_integration_tests" => true
}
)
# Wait for the pipeline to complete
result = circleci_wait_for_pipeline(
pipeline_id: pipeline["id"],
timeout: 1800, # 30 minutes
poll_interval: 30 # Check status every 30 seconds
)
if result[:status] == "success"
UI.success("Pipeline completed successfully!")
else
UI.error("Pipeline failed with status: #{result[:status]}")
end
Managing Environment Variables
# Set an environment variable
circleci_set_env_var(
project_slug: "github/myorg/myrepo",
name: "DEPLOY_KEY",
value: ENV["MY_DEPLOY_KEY"]
)
# Get all environment variables
env_vars = circleci_get_env_vars(
project_slug: "github/myorg/myrepo"
)
# Check if a variable exists
has_api_key = env_vars.any? { |var| var["name"] == "API_KEY" }
Working with Contexts
# List all contexts
contexts = circleci_list_contexts(
owner_slug: "github/myorg"
)
# Get a specific context by name
deploy_context = contexts.find { |ctx| ctx["name"] == "deploy-context" }
if deploy_context
# Add an environment variable to the context
circleci_add_context_env_var(
context_id: deploy_context["id"],
env_var_name: "RELEASE_TOKEN",
env_var_value: ENV["RELEASE_TOKEN"]
)
end
Downloading Artifacts
# Download only JSON files (default)
circleci_download_workflow_artifacts(
project_slug: "github/myorg/myrepo"
)
# Download only XML files
circleci_download_workflow_artifacts(
project_slug: "github/myorg/myrepo",
file_extensions: "xml"
)
# Download both JSON and XML files
circleci_download_workflow_artifacts(
project_slug: "github/myorg/myrepo",
file_extensions: ["json", "xml"]
)
# Download artifacts from a specific job only
circleci_download_workflow_artifacts(
project_slug: "github/myorg/myrepo",
job_name: "build"
)
# Download all artifacts from a specific workflow
artifacts_info = circleci_download_workflow_artifacts(
project_slug: "github/myorg/myrepo",
branch: "master",
workflow_name: "test",
destination_dir: "./artifacts"
)
# Check how many artifacts were downloaded
UI.message("Downloaded #{artifacts_info[:total_artifacts]} artifacts from #{artifacts_info[:workflow_name]} workflow")
# Process downloaded artifacts if needed
artifacts_info[:downloaded_artifacts].each do |job_artifacts|
job_name = job_artifacts[:job_name]
job_artifacts[:artifacts].each do |artifact|
path = artifact[:download_path]
# Process artifact files as needed
puts "Processing #{path} from job #{job_name}"
end
end
# Get artifacts from a job
artifacts = circleci_get_job_artifacts(
project_slug: "github/myorg/myrepo",
job_number: "123"
)
# Download a specific artifact
if artifacts.any?
test_results = artifacts.find { |a| a["path"].end_with?("test-results.xml") }
if test_results
circleci_download_artifact(
artifact_url: test_results["url"],
destination_path: "./test-results/circle-results.xml"
)
end
end
Working with Pipeline Schedules
# Create a pipeline schedule to run nightly
circleci_create_pipeline_schedule(
project_slug: "github/myorg/myrepo",
name: "Nightly Build",
description: "Runs every night at midnight",
timetable: {
per_hour: 1,
hours_of_day: [0],
days_of_week: [1, 2, 3, 4, 5]
},
branch: "main",
parameters: {
"deploy_env" => "staging"
}
)
# List all schedules for a project
schedules = circleci_list_pipeline_schedules(
project_slug: "github/myorg/myrepo"
)
# Find a specific schedule by name
nightly_build = schedules.find { |schedule| schedule["name"] == "Nightly Build" }
Working with Project Insights
# Get flaky tests for a project
flaky_tests = circleci_get_flaky_tests(
project_slug: "github/myorg/myrepo"
)
# Take action on flaky tests
if flaky_tests["most_failed_tests"].any?
UI.important("Found #{flaky_tests["most_failed_tests"].count} flaky tests that need attention")
flaky_tests["most_failed_tests"].each do |test|
puts " - #{test["test_name"]}: Failed #{test["times_flaked"]} times"
end
end
# Get workflow metrics
workflow_metrics = circleci_get_project_workflow_metrics(
project_slug: "github/myorg/myrepo",
branch: "main",
reporting_window: "last-30-days"
)
Run tests for this plugin
To run both the tests, and code style validation, run
rake
To automatically fix many of the styling issues, use
rubocop -a
Issues and Feedback
For any other issues and feedback about this plugin, please submit it to this repository.
Troubleshooting
If you have trouble using plugins, check out the Plugins Troubleshooting guide.
Using fastlane Plugins
For more information about how the fastlane
plugin system works, check out the Plugins documentation.
About fastlane
fastlane is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out fastlane.tools.