Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
buildPlugin(configurations: buildPlugin.recommendedConfigurations())

buildPlugin(
configurations: [
[platform: 'linux', jdk: 11],
[platform: 'windows', jdk: 11],
])
10 changes: 4 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.37</version>
<version>4.54</version>
<relativePath />
</parent>
<artifactId>global-post-script</artifactId>
<version>1.1.5-SNAPSHOT</version>
<version>1.1.6-SNAPSHOT</version>
<packaging>hpi</packaging>

<url>https://wiki.jenkins-ci.org/display/JENKINS/Global+Post+Script+Plugin</url>
Expand All @@ -23,8 +23,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.level>8</java.level>
<jenkins.version>2.303.3</jenkins.version>
<jenkins.version>2.375.2</jenkins.version>
Copy link
Contributor

@MarkEWaite MarkEWaite Feb 7, 2023

Choose a reason for hiding this comment

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

The "Choosing a Jenkins version" page recommends 2.361.4 when making the transition to Java 11 and plugin bill of materials.

Suggested change
<jenkins.version>2.375.2</jenkins.version>
<jenkins.version>2.361.4</jenkins.version>

</properties>

<developers>
Expand Down Expand Up @@ -65,7 +64,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5</version>
<configuration>
<goals>deploy</goals>
</configuration>
Expand All @@ -82,7 +80,7 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.10</version>
<version>3.0.16</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void onCompleted(Run run, TaskListener listener) {
}

String script = getDescriptorImpl().getScript();
File file = new File(Jenkins.getInstance().getRootDir().getAbsolutePath() + SCRIPT_FOLDER, script);
File file = new File(Jenkins.get().getRootDir().getAbsolutePath() + SCRIPT_FOLDER, script);
if (file.exists()) {
try {
BadgeManager manager = new BadgeManager(run, listener);
Expand Down Expand Up @@ -83,7 +83,7 @@ public Descriptor<GlobalPostScript> getDescriptor() {
}

public DescriptorImpl getDescriptorImpl() {
return (DescriptorImpl) Jenkins.getInstance().getDescriptorOrDie(GlobalPostScript.class);
return (DescriptorImpl) Jenkins.get().getDescriptorOrDie(GlobalPostScript.class);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -141,11 +141,11 @@ public void triggerJob(String jobName, Map<String, String> params) {
for (Map.Entry<String, String> entry : params.entrySet()) {
newParams.add(new StringParameterValue(entry.getKey(), entry.getValue()));
}
AbstractProject job = Jenkins.getInstance().getItem(jobName, run.getParent().getParent(), AbstractProject.class);
AbstractProject job = Jenkins.get().getItem(jobName, run.getParent().getParent(), AbstractProject.class);
if (null != job) {
Cause cause = new Cause.UpstreamCause(run);
boolean scheduled = job.scheduleBuild(job.getQuietPeriod(), cause, new ParametersAction(newParams));
if (Jenkins.getInstance().getItemByFullName(job.getFullName()) == job) {
if (Jenkins.get().getItemByFullName(job.getFullName()) == job) {
String name = ModelHyperlinkNote.encodeTo(job) + " "
+ ModelHyperlinkNote.encodeTo(
job.getAbsoluteUrl() + job.getNextBuildNumber() + "/",
Expand Down Expand Up @@ -201,7 +201,7 @@ public String getCause() {
}
}

String rootUrl = Jenkins.getInstance().getRootUrl();
String rootUrl = Jenkins.get().getRootUrl();
if (StringUtils.isNotEmpty(rootUrl)) {
cause.append("on ").append(rootUrl).append(" ");
}
Expand All @@ -226,6 +226,7 @@ public DescriptorImpl() {
}

public FormValidation doCheckScript(@QueryParameter("script") String name) throws IOException, ServletException {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the fix that I had missed in my earlier comment.

if (StringUtils.isEmpty(name)) {
return FormValidation.error("Please set the script name");
}
Expand All @@ -238,7 +239,7 @@ public FormValidation doCheckScript(@QueryParameter("script") String name) throw
public ComboBoxModel doFillScriptItems() {
ComboBoxModel items = new ComboBoxModel();

File scriptFolder = new File(Jenkins.getInstance().getRootDir().getAbsolutePath() + SCRIPT_FOLDER);
File scriptFolder = new File(Jenkins.get().getRootDir().getAbsolutePath() + SCRIPT_FOLDER);
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
String fileName = name.toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static String getIconPath(String icon) {
return null;
}

PluginWrapper wrapper = Jenkins.getInstance().getPluginManager().getPlugin(GlobalPostScriptPlugin.class);
PluginWrapper wrapper = Jenkins.get().getPluginManager().getPlugin(GlobalPostScriptPlugin.class);
boolean pluginIconExists = (wrapper != null) && new File(wrapper.baseResourceURL.getPath() + "/img/" + icon).exists();
return pluginIconExists ? "/plugin/global-post-script/img/" + icon : Jenkins.RESOURCE_PATH + "/images/16x16/" + icon;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ public void run(File scriptFile,
}

protected ClassLoader getGroovyClassloader() {
if (null == Jenkins.getInstance()) {
try {
Jenkins.get();
}
catch (IllegalStateException e){
return getParentClassloader();
}

File libFolder = new File(Jenkins.getInstance().getRootDir().getAbsolutePath() + GlobalPostScript.SCRIPT_FOLDER, "lib");
File libFolder = new File(Jenkins.get().getRootDir().getAbsolutePath() + GlobalPostScript.SCRIPT_FOLDER, "lib");
return getGroovyClassloader(libFolder);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.orctom.jenkins.plugin.globalpostscript.runner;

import com.orctom.jenkins.plugin.globalpostscript.GlobalPostScript;
import groovy.lang.GroovyClassLoader;
import hudson.model.TaskListener;
import jenkins.model.Jenkins;

Expand All @@ -24,9 +23,10 @@ protected void println(TaskListener listener, String message) {
}

protected ClassLoader getParentClassloader() {
if (null != Jenkins.getInstance()) {
return Jenkins.getInstance().getPluginManager().uberClassLoader;
} else {
try {
return Jenkins.get().getPluginManager().uberClassLoader;
}
catch (IllegalStateException e){
return Thread.currentThread().getContextClassLoader();
}
}
Expand Down