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.
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.
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.
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.
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.
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.
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.
No specific reason. Changed to setters 👌🏼
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-incompatiblelabel attached.do-not-merge/label attached.kind/andseverity/labels attached at least.