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

[JENKINS-41516] Add script console listener #6539

Closed
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e745089
Set location for listener
meiswjn Apr 26, 2022
060fe1e
Add ScriptListener
meiswjn May 4, 2022
89ac091
Remove debugging statements
meiswjn May 4, 2022
2aed668
Merge branch 'master' into feature/add-script-console-listener
meiswjn May 4, 2022
8d41ad1
Add listener for CLI
meiswjn May 9, 2022
5160902
Merge branch 'master' into feature/add-script-console-listener
meiswjn May 9, 2022
6b86d43
Merge branch 'jenkinsci:master' into feature/add-script-console-listener
meiswjn Jun 10, 2022
dc7728f
Add new listener for other sources
meiswjn Jun 23, 2022
c533407
Simplify listener
meiswjn Jun 23, 2022
8e9e618
Merge branch 'master' into feature/add-script-console-listener
meiswjn Jun 24, 2022
02ffdd1
Fix whitespace and comments
meiswjn Jun 24, 2022
0ceef7c
Merge branch 'feature/add-script-console-listener' of https://github.…
meiswjn Jun 24, 2022
d30108d
Merge branch 'master' into feature/add-script-console-listener
daniel-beck Jul 18, 2022
a2ede02
Merge branch 'master' into feature/add-script-console-listener
daniel-beck Jul 31, 2022
70b1334
Update core/src/main/java/hudson/cli/GroovyCommand.java
meiswjn Aug 11, 2022
eadd842
Add precise origins; Correctly log CLI input
meiswjn Aug 11, 2022
cc4ce09
Merge branch 'jenkinsci:master' into feature/add-script-console-listener
meiswjn Aug 11, 2022
a4a541c
Merge branch 'feature/add-script-console-listener' of https://github.…
meiswjn Aug 11, 2022
301dea2
Add LoggingGroovySh as suggested by @daniel-beck
meiswjn Aug 11, 2022
f1e5b03
Add ScriptListener Tests
meiswjn Aug 12, 2022
fcf5506
Merge branch 'master' into feature/add-script-console-listener
meiswjn Aug 25, 2022
df5b49c
Merge branch 'master' into feature/add-script-console-listener
basil Aug 25, 2022
567e03b
Add basic default listener that just logs
daniel-beck Aug 31, 2022
0526568
Merge branch 'master' into feature/add-script-console-listener
meiswjn Oct 7, 2022
19e7c04
Merge branch 'master' into feature/add-script-console-listener
meiswjn Nov 7, 2022
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
2 changes: 2 additions & 0 deletions core/src/main/java/jenkins/model/Jenkins.java
Original file line number Diff line number Diff line change
Expand Up @@ -4694,6 +4694,7 @@ public void run() {
* Run arbitrary Groovy script.
*/
public void doScript(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {

_doScript(req, rsp, req.getView(this, "_script.jelly"), FilePath.localChannel, getACL());
}

Expand Down Expand Up @@ -4722,6 +4723,7 @@ public static void _doScript(StaplerRequest req, StaplerResponse rsp, RequestDis
}

try {
ScriptListener.fireScriptEvent(req);
meiswjn marked this conversation as resolved.
Show resolved Hide resolved
req.setAttribute("output",
RemotingDiagnostics.executeGroovy(text, channel));
} catch (InterruptedException e) {
Expand Down
34 changes: 34 additions & 0 deletions core/src/main/java/jenkins/model/ScriptListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package jenkins.model;

import hudson.ExtensionPoint;
import jenkins.util.Listeners;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.StaplerRequest;

/**
* A listener to track usage of the script console.
*
* @see Jenkins#_doScript(StaplerRequest, org.kohsuke.stapler.StaplerResponse, javax.servlet.RequestDispatcher, hudson.remoting.VirtualChannel, hudson.security.ACL)
*/
public interface ScriptListener extends ExtensionPoint {

/**
* Called when script is executed in Script console.
*
* @see Jenkins#_doScript(StaplerRequest, org.kohsuke.stapler.StaplerResponse, javax.servlet.RequestDispatcher, hudson.remoting.VirtualChannel, hudson.security.ACL)
* @param req The StaplerRequest (POST) that contains the script to be executed.
*/
void onScript(StaplerRequest req);

/**
* Fires the {@link #onScript(StaplerRequest)} event to track the usage of the script console.
*
* @see Jenkins#_doScript(StaplerRequest, org.kohsuke.stapler.StaplerResponse, javax.servlet.RequestDispatcher, hudson.remoting.VirtualChannel, hudson.security.ACL)
* @param req The StaplerRequest (POST) that contians the script to be executed.
*/
@Restricted(NoExternalUse.class)
static void fireScriptEvent(StaplerRequest req) {
Listeners.notify(ScriptListener.class, true, listener -> listener.onScript(req));
}
}