Jenkins
Run Infracost in Jenkins to see cloud cost estimates and FinOps best practices in pull requests. Works with GitHub and Bitbucket (Cloud and Server).
GitHub users should consider the GitHub App instead — it's simpler to set up and faster to run. If you use Jenkins with Azure Repos or GitLab, email us so we can discuss your requirements.
Quick start
-
Install the Infracost CLI and run
infracost auth loginto get a free API key. Retrieve it withinfracost configure get api_key. -
In Jenkins (or wherever you store credentials), create a credential called
infracost-api-keycontaining your Infracost API key. -
Create a credential for posting PR comments. The name and value depend on your provider:
- GitHub —
github-token. Create a Personal Access Token withreposcope. If you use SAML SSO, authorize the token. - Bitbucket Cloud —
bitbucket-app-passwordorbitbucket-access-token. Use either an App password (recommended) with read+write access for Repositories and Pull requests, or a Repository access token with the same scopes. - Bitbucket Server —
bitbucket-access-token. Use an HTTP access token. Read-only repository permission is enough — Atlassian's docs note that "comment on a pull request" is allowed at that level.
- GitHub —
-
Add a Jenkinsfile to your repo. Use the example that matches your provider:
Each Jenkinsfile has two key stages — one that runs on pull requests and posts a comment, and another that runs on the main/master branch to upload results to Infracost Cloud.
noteThe GitHub Jenkinsfile example was developed for cases where there are no pull requests (jobs run on feature branches directly). If you use pull requests with GitHub, email us so we can update it for you.
-
Open a test PR — see these steps for what to expect.
Private Terraform modules
If your project uses private Terraform modules, you'll need to configure the Jenkins pipeline to fetch them. See Terraform modules for details.
Comment options
The Infracost CLI can post comments to GitHub, GitLab, Azure Repos, and Bitbucket. Run infracost comment --help for the full list of options, or see Comment on pull requests.