Skip to content

CI provider spec gaps: missing ci.job.id, git.pull_request.base_branch, git.commit.head.sha, and Drone support #16834

@gnufede

Description

@gnufede

Summary

The Shepherd CI provider spec runs a cross-tracer conformance test suite that validates CI provider tag extraction against a shared spec. dd-trace-py currently has 46 failing tests across 5 categories of missing tags.

Run details: https://github.com/DataDog/shepherd/actions/workflows/ci-spec.yaml


Failing Cases

1. ci.job.id missing — CircleCI (28 cases)

extract_circle_ci sets PIPELINE_NUMBER from CIRCLE_BUILD_NUM but does not set JOB_ID.

Expected: ci.job.id = CIRCLE_BUILD_NUM

Fix:

# in extract_circle_ci
JOB_ID: env.get("CIRCLE_BUILD_NUM"),

2. ci.job.id missing — AWS CodePipeline (1 case)

extract_codebuild does not set JOB_ID.

Expected: ci.job.id = DD_ACTION_EXECUTION_ID

Fix:

# in extract_codebuild (awscodepipeline branch)
JOB_ID: env.get("DD_ACTION_EXECUTION_ID"),

3. Drone CI not implemented (2 cases)

There is no extract_drone function and no "DRONE" entry in PROVIDERS. Both basic and PR test cases fail.

Fix: Add a new provider:

def extract_drone(env):
    return {
        PROVIDER_NAME: "drone",
        PIPELINE_NUMBER: env.get("DRONE_BUILD_NUMBER"),
        PIPELINE_URL: env.get("DRONE_BUILD_LINK"),
        JOB_NAME: env.get("DRONE_STEP_NAME"),
        STAGE_NAME: env.get("DRONE_STAGE_NAME"),
        WORKSPACE_PATH: env.get("DRONE_WORKSPACE"),
        git.REPOSITORY_URL: env.get("DRONE_GIT_HTTP_URL"),
        git.COMMIT_SHA: env.get("DRONE_COMMIT_SHA"),
        git.BRANCH: env.get("DRONE_BRANCH"),
        git.TAG: env.get("DRONE_TAG"),
        git.COMMIT_MESSAGE: env.get("DRONE_COMMIT_MESSAGE"),
        git.COMMIT_AUTHOR_NAME: env.get("DRONE_COMMIT_AUTHOR_NAME"),
        git.COMMIT_AUTHOR_EMAIL: env.get("DRONE_COMMIT_AUTHOR_EMAIL"),
        git.PULL_REQUEST_BASE_BRANCH: env.get("DRONE_TARGET_BRANCH"),
    }

And add ("DRONE", extract_drone) to PROVIDERS.


4. git.pull_request.base_branch missing — 6 cases across 5 providers

The constant git.PULL_REQUEST_BASE_BRANCH does not exist in ddtrace/ext/git.py, and no extract function populates this tag. Failing providers and their source env vars:

Provider Env var Spec case
usersupplied DD_GIT_PULL_REQUEST_BASE_BRANCH usersupplied:16
github GITHUB_BASE_REF github:24
buddy BUDDY_TARGET_BRANCH buddy:15
azurepipelines SYSTEM_PULLREQUEST_TARGETBRANCH azurepipelines:28
jenkins CHANGE_TARGET jenkins:35
drone DRONE_TARGET_BRANCH drone:1

Fix: Add constant to ddtrace/ext/git.py:

PULL_REQUEST_BASE_BRANCH = "git.pull_request.base_branch"

Then populate in each provider's extract_* function.


5. git.commit.head.sha missing — AppVeyor (2 cases)

extract_appveyor does not read APPVEYOR_PULL_REQUEST_HEAD_COMMIT into git.COMMIT_HEAD_SHA, even though the constant already exists.

Expected: git.commit.head.sha = APPVEYOR_PULL_REQUEST_HEAD_COMMIT

Fix:

# in extract_appveyor
git.COMMIT_HEAD_SHA: env.get("APPVEYOR_PULL_REQUEST_HEAD_COMMIT"),

Reproduction

The spec fixtures and test runner live in https://github.com/DataDog/shepherd. To reproduce locally:

# Generate fixtures
scripts/generate-ci-fixtures

# Copy to dd-trace-py
cp specs/ci-providers/generated/*.json tests/tracer/fixtures/ci/

# Run tests
pip install -e .
pip install mock pytest pytest-cov hypothesis
pytest -k test_ci_providers tests/tracer/test_ci.py

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions