Skip to content

Add ci-env read subcommand to print extracted CI env info#2123

Merged
Bit-Doctor merged 3 commits intomasterfrom
jonathan.machado/add_read-ci-env_subcmd
Feb 20, 2026
Merged

Add ci-env read subcommand to print extracted CI env info#2123
Bit-Doctor merged 3 commits intomasterfrom
jonathan.machado/add_read-ci-env_subcmd

Conversation

@Bit-Doctor
Copy link
Contributor

@Bit-Doctor Bit-Doctor commented Feb 19, 2026

What and why?

This PR adds a new ci-env read command that extracts CI-specific environment variables from various CI providers (GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, etc.) and outputs them in a normalized DD_CI_* and DD_GIT_* format.

Why: CI environment variables are inconsistent across providers (e.g., TRAVIS_JOB_WEB_URL, GITHUB_RUN_ID, CIRCLE_BUILD_NUM). This command normalizes them into a consistent format that can be:

  • Debugging: View all extracted CI metadata in a readable format to troubleshoot CI detection issues
  • Passing to other commands: Provide normalized CI context to any command that needs CI metadata

Supports three output formats:

  • bash (default): .env file format - DD_CI_JOB_NAME='deploy-prod'
  • json: JSON object for programmatic processing
  • tags: Datadog internal tag format - ci.job.name:"deploy-prod"

How?

  • Leverages existing getCISpanTags(), getUserCISpanTags(), and getUserGitSpanTags() functions from helpers/ci.ts and helpers/user-provided-git.ts
  • Uses explicit mapping objects (TAG_TO_ENV_VAR) to translate internal tag keys (e.g., ci.job.url) to environment variables (e.g., DD_CI_JOB_URL)
  • Implements format-specific escape functions:
    • escapeBashValue(): Single-quote escaping to prevent variable expansion/command injection
    • escapeTagValue(): Double-quote and backslash escaping for tag format
  • Merges CI-detected tags with user-provided tags, with user-provided taking precedence
  • All existing data sanitization (repository URL filtering, branch/tag normalization) is inherited from getCISpanTags()

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)

@Bit-Doctor Bit-Doctor requested a review from a team as a code owner February 19, 2026 18:21
@Bit-Doctor Bit-Doctor force-pushed the jonathan.machado/add_read-ci-env_subcmd branch from 8675f0d to cc182bd Compare February 19, 2026 18:42
@datadog-official
Copy link

datadog-official bot commented Feb 19, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 509ff2d | Docs | Datadog PR Page | Was this helpful? Give us feedback!

@Bit-Doctor Bit-Doctor added the datadog-ci For PRs spanning multiple commands, and repo-wide changes label Feb 19, 2026
Copy link
Contributor

@Drarig29 Drarig29 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly nits, otherwise it looks good!

Comment on lines +157 to +163
examples: [
['Set variables in current shell', 'eval "$(datadog-ci ci-env read)"'],
['Save as .env file for Docker', 'datadog-ci ci-env read > .env'],
['Use with shell scripts', 'datadog-ci ci-env read > ci.env && source ci.env'],
['Get JSON output', 'datadog-ci ci-env read --format json'],
['Get Datadog tags format', 'datadog-ci ci-env read --format tags'],
],
Copy link
Contributor

@Drarig29 Drarig29 Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested all those examples locally with export GITHUB_ACTION=1; export GITHUB_JOB=abc;, and it works properly 👍

Copy link
Contributor

@Drarig29 Drarig29 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Bit-Doctor Bit-Doctor merged commit 1f60897 into master Feb 20, 2026
26 checks passed
@Bit-Doctor Bit-Doctor deleted the jonathan.machado/add_read-ci-env_subcmd branch February 20, 2026 18:40
@Bit-Doctor Bit-Doctor changed the title Add read-ci-env subcommand to print extracted CI env info Add ci-env read subcommand to print extracted CI env info Feb 20, 2026
@vishal-joshi-datadog vishal-joshi-datadog mentioned this pull request Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

datadog-ci For PRs spanning multiple commands, and repo-wide changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants