jenkinsci / jenkinsci/send-stacktrace-to-eclipse-plugin

[JENKINS-74565] [send-stacktrace-to-eclipse-plugin] Extract inline script block in org/jenkinsci/plugins/send_to_eclipse/SendToEclipse/header.jelly

Open
#21 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1
Forks
3
PR merge metrics
No merged PRs in 30d

Description

Problem

```
== Inline Script Block
Line: 4
----

(function($) {
var eclipseURL = "http://localhost:58642";

$(document).ready(function() {
// Handler for .ready() called.
var request = $.ajax({
url : eclipseURL + "/postevent"
});
request.done(function(data) {
$( "#footer" ).prepend( '<span style="padding-right:2em; color:gray"><img src="' + eclipseURL + '/icon" style="padding-right:2px;"/> <a href="http://cbos.github.io/OpenFromExternalEvent/">Eclipse integration</a> is enabled.</span>' );
addSendToEclipse();
});
request.fail(function(jqXHR, textStatus) {
$( "#footer" ).prepend( '<span style="padding-right:2em; color:gray"><a href="http://cbos.github.io/OpenFromExternalEvent/">Eclipse integration</a> is not enabled.</span>' );
});
});

function addSendToEclipse()
{
//Test Summary page
var h1TestResult = $( "h1:contains('Test Result')" );
if(h1TestResult.length > 0)
{
addEclipseForSummarPage()
}

//Page with single test content
var h1Failed = $( "h1:contains('Failed'), h1:contains('Regression')" );
if(h1Failed.length > 0)
{
addEclipseForTestDetailsPage(h1Failed)
}
}

function addEclipseForSummarPage()
{
$('a[title="Show details"]').click(function()
{
//Once the link is clicked the HTML has to be rendered, after that we can add the Eclipse icon
//Try max 20 attempts, first attempt after 100 millis
window.setTimeout(addEclipseAfterContentLoaded(this,20), 100);
});

//Select all links (with class model-link inside) direct after a link with title "Hide details"
$('a[title="Hide details"] + a[class="model-link inside"]').each(function() {
var element = $(this);
appendEclipseImage(element);
addPostHandler(element.children().last(), element);
});
}

function addEclipseAfterContentLoaded(element, iteration)
{
return function()
{
var linksWithStackTrace = $(element).parent().find( "h4 a:contains('Stack Trace')" );
if(linksWithStackTrace.length > 0)
{
var h4Element = linksWithStackTrace.parent();
appendEclipseImage(h4Element);
addPostHandler(h4Element.children().last(), h4Element.next());
}
else
{
if(iteration != 0) //use this construction as great then or less then symbol cannot be just due to Jenkins
{
window.setTimeout(addEclipseAfterContentLoaded(element, iteration-1), 100); //next attempt after 100 millis
}
}
}
}

function addEclipseForTestDetailsPage(h1Failed)
{
var paragraphInH1 = h1Failed.next();
appendEclipseImage(paragraphInH1);
addPostHandler(paragraphInH1.children().last(), paragraphInH1.first());

var stackTraceElement = $( "h3:contains('Stacktrace')" );
if(stackTraceElement.length > 0)
{
appendEclipseImage(stackTraceElement);
addPostHandler(stackTraceElement.children().last(), stackTraceElement.next());
}
}

function appendEclipseImage(element)
{
element.append('<img src="' + eclipseURL + '/icon" style="padding-left:2px;cursor: pointer; cursor: hand;" title="Send Stacktrace/testclass to Eclipse" />');
}

function addPostHandler(element, elementWithContent)
{
element.click(function( event ) {
postToEclipse(elementWithContent.text());
return false; //prevent bubble up
});
}

function postToEclipse( text )
{
$.post( eclipseURL + "/postevent", text );
}
})(jQuery)

----

```

Solution

https://www.jenkins.io/doc/developer/security/csp/#inline-javascript-blocks

---
Originally reported by basil, imported from: [send-stacktrace-to-eclipse-plugin] Extract inline script block in org/jenkinsci/plugins/send_to_eclipse/SendToEclipse/header.jelly


  • status: Open
  • priority: Minor
  • component(s): _unsorted
  • label(s): CSP
  • resolution: Unresolved
  • votes: 0
  • watchers: 1
  • imported: 2025-12-08

Raw content of original issue

Problem


== Inline Script Block

Line: 4
----
<script>
(function($) {
var eclipseURL = "http://localhost:58642";

$(document).ready(function() {
// Handler for .ready() called.
var request = $.ajax({
url : eclipseURL + "/postevent"
});
request.done(function(data) {
$( "#footer" ).prepend( '<span style="padding-right:2em; color:gray"><img src="' + eclipseURL + '/icon" style="padding-right:2px;"/> <a href="http://cbos.github.io/OpenFromExternalEvent/">Eclipse integration</a> is enabled.</span>' );
addSendToEclipse();
});
request.fail(function(jqXHR, textStatus) {
$( "#footer" ).prepend( '<span style="padding-right:2em; color:gray"><a href="http://cbos.github.io/OpenFromExternalEvent/">Eclipse integration</a> is not enabled.</span>' );
});
});

function addSendToEclipse()
{
//Test Summary page
var h1TestResult = $( "h1:contains('Test Result')" );
if(h1TestResult.length > 0)
{
addEclipseForSummarPage()
}

//Page with single test content
var h1Failed = $( "h1:contains('Failed'), h1:contains('Regression')" );
if(h1Failed.length > 0)
{
addEclipseForTestDetailsPage(h1Failed)
}
}

function addEclipseForSummarPage()
{
$('a[title="Show details"]').click(function()
{
//Once the link is clicked the HTML has to be rendered, after that we can add the Eclipse icon
//Try max 20 attempts, first attempt after 100 millis
window.setTimeout(addEclipseAfterContentLoaded(this,20), 100);
});

//Select all links (with class model-link inside) direct after a link with title "Hide details"
$('a[title="Hide details"] + a[class="model-link inside"]').each(function() {
var element = $(this);
appendEclipseImage(element);
addPostHandler(element.children().last(), element);
});
}

function addEclipseAfterContentLoaded(element, iteration)
{
return function()
{
var linksWithStackTrace = $(element).parent().find( "h4 a:contains('Stack Trace')" );
if(linksWithStackTrace.length > 0)
{
var h4Element = linksWithStackTrace.parent();
appendEclipseImage(h4Element);
addPostHandler(h4Element.children().last(), h4Element.next());
}
else
{
if(iteration != 0) //use this construction as great then or less then symbol cannot be just due to Jenkins
{
window.setTimeout(addEclipseAfterContentLoaded(element, iteration-1), 100); //next attempt after 100 millis
}
}
}
}

function addEclipseForTestDetailsPage(h1Failed)
{
var paragraphInH1 = h1Failed.next();
appendEclipseImage(paragraphInH1);
addPostHandler(paragraphInH1.children().last(), paragraphInH1.first());

var stackTraceElement = $( "h3:contains('Stacktrace')" );
if(stackTraceElement.length > 0)
{
appendEclipseImage(stackTraceElement);
addPostHandler(stackTraceElement.children().last(), stackTraceElement.next());
}
}

function appendEclipseImage(element)
{
element.append('<img src="' + eclipseURL + '/icon" style="padding-left:2px;cursor: pointer; cursor: hand;" title="Send Stacktrace/testclass to Eclipse" />');
}

function addPostHandler(element, elementWithContent)
{
element.click(function( event ) {
postToEclipse(elementWithContent.text());
return false; //prevent bubble up
});
}

function postToEclipse( text )
{
$.post( eclipseURL + "/postevent", text );
}
})(jQuery)
</script>
----


Solution

https://www.jenkins.io/doc/developer/security/csp/#inline-javascript-blocks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.