-
Notifications
You must be signed in to change notification settings - Fork 49
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
Allow setting Git information via environment variables #252
Conversation
public static String getGitRepositoryUrl(final EnvVars envVars) { | ||
return getGitRepositoryUrl(envVars.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to GitUtils
class with the logic to select the correct env var (either user supplied env var or jenkins env var)
dc693d1
to
a98fbdb
Compare
* @param envVars | ||
* @return map | ||
*/ | ||
public static Map<String, String> toMap(EnvVars envVars) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EnvVars already implements Map<String, String>
according to https://javadoc.jenkins-ci.org/hudson/EnvVars.html
// These are the most common values the user will provide. | ||
return envVars.get(DD_GIT_REPOSITORY_URL) != null || | ||
envVars.get(DD_GIT_BRANCH) != null || | ||
envVars.get(DD_GIT_TAG) != null || | ||
envVars.get(DD_GIT_COMMIT_SHA) != null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this check is super consistent. If we are providing more env vars, I guess we should check all of them. For example, if the user is providing author information to adjust their billing I don't see why we should be ignoring it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to use all the user-supplied env vars.
setBranch(envVars.get("GIT_BRANCH")); | ||
setGitUrl(DatadogUtilities.getGitRepositoryUrl(envVars)); | ||
setGitCommit(envVars.get("GIT_COMMIT")); | ||
if (isGit(envVars)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is isGit
only called in BuildData but not in DatadogTracePipelineLogic?
if(getGitMessage("").isEmpty()){ | ||
this.gitMessage = gitCommitAction.getMessage(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why aren't you using the setters here?
if(getGitMessage("").isEmpty()){ | |
this.gitMessage = gitCommitAction.getMessage(); | |
} | |
setGitMessage(getGitMessage(gitCommitAction.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No specific reason. Changed to setters 👌🏼
src/main/java/org/datadog/jenkins/plugins/datadog/model/BuildData.java
Outdated
Show resolved
Hide resolved
This method is used in The logic of the |
Requirements for Contributing to this repository
What does this PR do?
This PR adds the logic to allow the user to set Git information via environment variables.
These variables are optional, but if they are set, they take precedence over the same git information that Jenkins could provide.
Description of the Change
Alternate Designs
Possible Drawbacks
Verification Process
Additional Notes
Release Notes
Review checklist (to be filled by reviewers)
changelog/
label attached. If applicable it should have thebackward-incompatible
label attached.do-not-merge/
label attached.kind/
andseverity/
labels attached at least.