Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

branch tag missing on metrics and events #334

Closed
drmaciej opened this issue Feb 26, 2023 · 6 comments
Closed

branch tag missing on metrics and events #334

drmaciej opened this issue Feb 26, 2023 · 6 comments
Assignees
Labels
kind/bug Bug related issue

Comments

@drmaciej
Copy link

Describe the bug
branch is not set as a a tag on any metric, and it is not set on any events.

Screenshots
My plugin config is pretty much the defaults:
Screenshot 2023-02-27 at 9 15 18 am

nothing else is changed.

I also have an env var set in Jenkins:

          - name: DATADOG_JENKINS_PLUGIN_TARGET_HOST
            valueFrom:
              fieldRef:
                apiVersion: v1
                fieldPath: status.hostIP

Environment and Versions (please complete the following information):
Jenkins 2.375.3, on EKS 1.22
plugin: 5.3.0

Additional context
On metrics, e.g. jenkins.job.completed I get all other documented tags: jenkins_url, job, node, result, user_id.
On events, e.g. "Build completed", I get all other documented tags as well: event_type, jenkins_url, job, node, result, user_id.

It looks like branch is consistently missing across the board. Can you provide any insight into how I can troubleshoot that? I'm aware I can set tags via https://github.com/jenkinsci/datadog-plugin#pipeline-customization, but didn't want to do it for a "built-in" tag.

@drmaciej drmaciej added the kind/bug Bug related issue label Feb 26, 2023
@adjshort
Copy link

I've noticed the same thing.

For us, it looks like pipelines using multibranch pipelines don't pick up the branch name, where the few that do have a branch tag set are just using the Git plugin to check out a repository.

If I've followed the flow correctly,

public static String resolveGitBranch(Map<String, String> envVars, BuildData buildData) {
if(StringUtils.isNotEmpty(envVars.get(DD_GIT_BRANCH))){
return envVars.get(DD_GIT_BRANCH);
} else if (StringUtils.isNotEmpty(envVars.get(GIT_BRANCH))){
return envVars.get(GIT_BRANCH);
} else if(buildData != null){
return buildData.getBranch("");
} else {
return null;
}
}
is using the environment variables DD_GIT_BRANCH and GIT_BRANCH, but not the one the multibranch pipeline plugin sets, BRANCH_NAME

@kivagant-ba
Copy link

If the DD_GIT_BRANCH is specified in a Jenkinsfile environment variable equal to BRANCH_NAME, will the plugin pick it up?

@chill389cc
Copy link

Did you ever figure out this issue?

@drmaciej
Copy link
Author

I actually cannot remember how I fixed it, but I do see the branch tag on both metrics and events, running the latest Jenkins version and the latest DD plugin version.

iirc one of the plugin versions had a fix for this issue and it just started working without any other intervention.

@sebastiaanspeck
Copy link

I am curious if anyone found out what the out-of-the-box fix is. I do seem to have a branch in my Events, but for multibranch-pipelines it looks like a random hash

@nikita-tkachenko-datadog
Copy link
Collaborator

Hi @sebastiaanspeck,
The hash string reported by the plugin was the SHA of the head commit of the checked out branch.
It was reported like this because Jenkins checks out a detached HEAD of the branch when running a multipipeline build.

A new version of the plugin (7.2.0) was released today, which adds a workaround that should help to detect proper branch names for such builds.
Let me know if the issue persists with the new version of the plugin.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Bug related issue
Projects
None yet
Development

No branches or pull requests

6 participants