DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • How to Manage Continuous Releases With Travis CI and Sentry.io
  • DevOps: CI/CD Tools to Watch Out for in 2022
  • Why Incorporate CI/CD Pipeline in Your SDLC?
  • Jenkins in the Age of Kubernetes: Strengths, Weaknesses, and Its Future in CI/CD

Trending

  • Hybrid Cloud vs Multi-Cloud: Choosing the Right Strategy for AI Scalability and Security
  • Solid Testing Strategies for Salesforce Releases
  • Beyond Linguistics: Real-Time Domain Event Mapping with WebSocket and Spring Boot
  • Streamlining Event Data in Event-Driven Ansible
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Automating Sentry Releases With CircleCI

Automating Sentry Releases With CircleCI

Continuous integration tools like CircleCI let developers automate builds and tests, so that teams can merge changes into their codebase quickly and frequently.

By 
Liz Krane user avatar
Liz Krane
·
Jun. 10, 20 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
7.2K Views

Join the DZone community and get the full member experience.

Join For Free

Continuous integration tools like CircleCI let developers automate builds and tests, so that teams can merge changes into their codebase quickly and frequently. In this article, we’ll take a look at how to combine Sentry’s command-line interface with CircleCI to automatically create Sentry releases. This will unlock some of our best features, like identifying suspect commits that likely introduced new errors, applying source maps to see the original source code within Sentry, and more.

Learn more about Sentry releases here.

Making a CircleCI Configuration File

If you’re new to CircleCI, follow their “getting started” guide — you’ll need to create a CircleCI account and link up your project’s repository, which can be hosted on GitHub or Bitbucket.

Your CircleCI build process is defined in a config.yml file, which needs to be in a .circleci/ directory. Here’s an example of a bare-bones config file:

YAML
 




x


 
1
version: 2
2
jobs:
3
  build:
4
    docker: 
5
      - image: circleci/node:4.8.2 # the primary container, where your job's commands are run
6
    steps:
7
      - checkout # check out the code in the project directory
8
      - run: echo "Hello world!" # run the `echo` command


CircleCI config files contain a list of jobs, which contain a series of steps to run. (Note: If you’re not using their workflows feature, at least one job needs to be named build.) Each job can also be executed in different environments: within a Docker image or within a virtual machine image for Linux, Mac, or Windows. The example above uses circleci/node:4.8.2, one of CircleCI’s predefined Docker images.

The steps value contains a list of key/value pairs, where the key defines the type of step. For example, the “checkout” step is a special pre-defined action that checks out the code from your project’s repository, automatically adding the required auth keys to interact with GitHub and Bitbucket over SSH.

To run Bash commands, you can either use a series of run steps, or you can include multiple commands within a single step:

Shell
 




xxxxxxxxxx
1


 
1
steps:
2
  - checkout # check out the code in the project directory
3
  - run: | 
4
      echo "Hello..."
5
      echo "...World!"


Note: CircleCI runs each step in a new shell, so environment variables are not shared across steps.

To run a CircleCI job only for certain branches, you can set the branches key to choose specific branches — for example, to run a job only when a commit is pushed to the master branch:

Shell
 




xxxxxxxxxx
1


 
1
build:
2
  branches:
3
    only:
4
      - master


Creating a Sentry Internal Integration

Our Integration Platform allows developers to connect Sentry with third-party tools — either as Public Integrations that anyone can use, or as Internal Integrations built only for one organization to combine Sentry with their internal tools and custom workflows.

To create a new Internal Integration, navigate to Settings > Developer Settings > New Internal Integration within Sentry. There, you’ll give your new integration a title (for example, “Create Sentry Releases with CircleCI”), choose which permissions to use, and get your token for authenticating with Sentry’s API.

Setting Permissions

You can apply different sets of permissions for each integration. For this one, we’ll need Admin access for “Release” and Read access for “Organization”:

See our docs page on permissions to learn more about scopes for Sentry’s API endpoints.

Next, click “Save” at the bottom of the page and then grab your token:

In the next section, we’ll use this Internal Integration token to enable CircleCI to authenticate with Sentry’s API when creating a new Release.

Creating a Sentry Release with CircleCI

You’ll first need to ensure that Sentry releases are set up for your Sentry project. The simplest way to connect your commit metadata to Sentry is to use our GitHub integration or our Bitbucket integration. (Note that CircleCI currently only supports GitHub and Bitbucket.)

Next, we’ll set a few environment variables to configure the Sentry CLI:

  • SENTRY_AUTH_TOKEN - Your Internal Integration token.
  • SENTRY_ORG - Your Sentry organization slug.
  • SENTRY_PROJECT - Your Sentry project slug.

To save any sensitive data like the SENTRY_AUTH_TOKEN, CircleCI provides a page for Build Settings in their admin backend. Any environment variables saved there will be redacted in your logs, appearing as **** so that private data can’t be revealed accidentally.

To save non-sensitive data in the build environment, use the environment key to define your environment variables in your config.yml file:

Shell
 




xxxxxxxxxx
1


 
1
build:
2
  environment:
3
    SENTRY_ORG: my-org
4
    SENTRY_PROJECT: my-project


Finally, to install the Sentry CLI on CircleCI’s virtual machine and create a new Sentry release, we’ll use the following Bash commands:

Shell
 




xxxxxxxxxx
1


 
1
run: |
2
  curl -sL https://sentry.io/get-cli/ | bash
3
  export SENTRY_RELEASE=$(sentry-cli releases propose-version)
4
  sentry-cli releases new -p $SENTRY_PROJECT $SENTRY_RELEASE
5
  sentry-cli releases set-commits --auto $SENTRY_RELEASE
6
  sentry-cli releases finalize $SENTRY_RELEASE


Here’s our complete example config.yml file that will create a new Sentry release every time a commit is pushed to the master branch:

YAML
 




xxxxxxxxxx
1
19


 
1
version: 2
2
jobs:
3
  build:
4
    docker: 
5
      - image: circleci/node:4.8.2
6
    environment:
7
      SENTRY_ORG: my-org
8
      SENTRY_PROJECT: my-project
9
    branches:
10
      only:
11
        - master
12
    steps:
13
      - checkout # check out the code in the project directory
14
      - run: | 
15
          curl -sL https://sentry.io/get-cli/ | bash
16
          export SENTRY_RELEASE=$(sentry-cli releases propose-version)
17
          sentry-cli releases new -p $SENTRY_PROJECT $SENTRY_RELEASE
18
          sentry-cli releases set-commits --auto $SENTRY_RELEASE
19
          sentry-cli releases finalize $SENTRY_RELEASE


Be sure to check out our documentation for more details about managing Sentry releases.

Testing CircleCI Configuration Files Locally

CircleCI provides a convenient command line interface for testing your config.yml file locally. YAML syntax errors are much easier to catch by testing your config.yml file locally, rather than pushing code to your repository and waiting for CircleCI’s servers to run your build each time.

To validate your config file locally, use the validate command:

Shell
 




xxxxxxxxxx
1


 
1
circleci config validate -c .circleci/config.yml


And to run a job locally, use the local execute command:

Shell
 




xxxxxxxxxx
1


 
1
circleci local execute --job "jobname"


Note: When running a build locally, CircleCI does not import any encrypted variables configured via their UI. They recommend setting those environment variables via the CLI in this format: circleci local execute --job "jobname" --env MY_VAR=MY_VALUE

You can also use git hooks to validate your CircleCI configuration file every time you make a commit; see CircleCI’s blog post for a walkthrough.

Be sure to reference CircleCI’s full configuration syntax guide to troubleshoot any tricky YAML issues.

Verifying That Your Sentry Releases Are Working

Push a new commit to the branch specified in your config.yml file to trigger CircleCI to run your build. You can view details about the build in CircleCI’s UI and see any errors listed there if it fails.

If the CircleCI build succeeded, head over to your Sentry organization and click “Releases” on the left-side menu. You should see a brand new release listed for your project, listing the SHA of your latest commit:

To confirm that new events from your project will be correctly associated with your releases, you can use the Sentry CLI to send an event for your project. If you run this from within your project’s git repository, the current release will be linked to the event automatically:

Shell
 




xxxxxxxxxx
1


 
1
export SENTRY_DSN=https://mydsnhere@sentry.io/1234
2
sentry-cli send-event -m "Test event, should be linked to the latest release"


See our docs for more about sending events with Sentry’s command line interface.

After sending the event, check your project’s “Releases” page again in Sentry. On the page for your latest release, you’ll see a new unresolved issue associated with the release:


Release (computing) Command-line interface Continuous Integration/Deployment file IO Integration shell

Published at DZone with permission of Liz Krane. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How to Manage Continuous Releases With Travis CI and Sentry.io
  • DevOps: CI/CD Tools to Watch Out for in 2022
  • Why Incorporate CI/CD Pipeline in Your SDLC?
  • Jenkins in the Age of Kubernetes: Strengths, Weaknesses, and Its Future in CI/CD

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!