Skip to content

Level 12#3

Open
sandeepbarnwal wants to merge 15 commits intomainfrom
level-12
Open

Level 12#3
sandeepbarnwal wants to merge 15 commits intomainfrom
level-12

Conversation

@sandeepbarnwal
Copy link
Owner

Copy link

@dwnusbaum dwnusbaum left a comment

Choose a reason for hiding this comment

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

Took a quick look and added some general feedback about things that I noticed. Nice work!

Comment on lines +113 to +124
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
</plugins>
</build>

Choose a reason for hiding this comment

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

Don't do this. Let the parent POM control the Java version, see https://github.com/jenkinsci/plugin-pom/blob/03cc96f91d5ddfa4b46acfc78267baf8895472d1/pom.xml#L61.

Copy link
Owner Author

@sandeepbarnwal sandeepbarnwal Nov 14, 2024

Choose a reason for hiding this comment

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

I think that this came as part of the jenkins plugin template and has not noticed.
Thanks for the observation and I'll update it to inherit it from the parent.

Comment on lines +88 to +98
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.11.0</version>
<exclusions>
<exclusion>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
</exclusion>
</exclusions>
</dependency>

Choose a reason for hiding this comment

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

Generally in Jenkins, avoid pulling in 3rd party Java libraries directly wherever possible. Prefer API plugins. See https://www.jenkins.io/doc/developer/plugin-development/dependencies-and-class-loading/#bundling-third-party-libraries and the next two headings. In Jenkins, basic JSON-related tasks can use https://github.com/jenkinsci/jenkins/blob/b0e47a7a9bf5b448bb906e7087cac841b2b5b144/core/pom.xml#L397-L400 (org.net.sf.json.JSONObject is the main class), and for more complicated cases you can use Jackson via https://plugins.jenkins.io/jackson2-api/.


private String username;

private String password;

Choose a reason for hiding this comment

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

Never use a String for secret values that get persisted. Either use the Secret type, or typically better is to have the user configure credentials separately and then just have the user configure the ID of the relevant credentials. See https://www.jenkins.io/doc/developer/security/secrets/.

Copy link
Owner Author

Choose a reason for hiding this comment

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

yeah, makes sense. I'll update it.

private static FormValidation invokeRestApiPost(String url, String authHeader, String payload) {
try {
HttpClient client = HttpClient.newHttpClient();
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()

Choose a reason for hiding this comment

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

FTR in Jenkins use these methods to create HttpClient instances to respect users' proxy configurations.

return url;
}

public void setUrl(String url) {

Choose a reason for hiding this comment

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

FWIW I think it is typical to use @DataBoundSetter for GlobalConfiguration setters and @DataBoundConstructor for the constructor, though perhaps it is not required? See for example https://github.com/jenkinsci/configuration-as-code-plugin/blob/8b9efc1b9026942064d5248c92bf89cb00f83ea0/plugin/src/main/java/io/jenkins/plugins/casc/CasCGlobalConfig.java#L38.

}
}

private void saveJobNamePerCategory(String jobName, String category) {

Choose a reason for hiding this comment

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

In Jenkins "Job" and "Run" mean two very distinct things, so it is important to be clear about what you mean. This is runFullDisplayName, not jobName.

Comment on lines +103 to +104
Type type = new TypeToken<Map<String,List<JobRunEntry>>>(){}.getType();
categoryJobsMap = gson.fromJson(reader, type);

Choose a reason for hiding this comment

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

Seeing the use case now, in this case probably the typical approach would just be to serialize this as XML instead using XStream from Jenkins core.

public ListBoxModel doFillSelectedCategoryItems() {
ListBoxModel items = new ListBoxModel();
OnboardingSectionConfiguration onboardingSectionConfig = GlobalConfiguration.all().get(OnboardingSectionConfiguration.class);
System.out.println(onboardingSectionConfig == null);

Choose a reason for hiding this comment

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

Make sure not to do this in real code.

}
```
2. Install pipeline-utility-steps
3. Approve method invocations from http://localhost:8080/jenkins/manage/scriptApproval/

Choose a reason for hiding this comment

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

If you ever have to approve methods on this page you are probably going down the wrong path. getBuildReferences and updateBuildReferences don't look like they belong in a Pipeline at all. I think the expectation was for this logic to be done internally in OnboardingTaskBuilder.

Comment on lines +56 to +59
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
</dependency>

Choose a reason for hiding this comment

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

I don't think you need this dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants