Created
October 10, 2018 14:18
-
-
Save imoutsatsos/859ac621d9055bf0dcfe7b6b7f6a6c9d to your computer and use it in GitHub Desktop.
Active Choices Reactive Parameter for parametrizing JavaScript from a Jenkins Global Variable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jenkins.* | |
import jenkins.model.* | |
import hudson.* | |
import hudson.model.* | |
import org.kohsuke.stapler.Stapler | |
import groovy.text.SimpleTemplateEngine | |
def sessionID= Stapler.getCurrentRequest().getSession().getId() | |
instance = Jenkins.getInstance() | |
globalNodeProperties = instance.getGlobalNodeProperties() | |
envVarsNodePropertyList = globalNodeProperties.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class) | |
envVars = envVarsNodePropertyList.get(0).getEnvVars() | |
osdJs= envVars['OPENSEADRAGON_JS'] | |
env=System.getenv() | |
helperJavaScriptTemplatePath="${env['JENKINS_HOME']}/jobs/${jenkinsProject.name}/buildScripts/imageGallery.jst" | |
helperJavaScriptTemplate= new File(helperJavaScriptTemplatePath as String) | |
def simple = new SimpleTemplateEngine() | |
def source = helperJavaScriptTemplate.text | |
def binding = [osdJs: osdJs] | |
def helperJavaScript= simple.createTemplate(source).make(binding).toString() | |
/* | |
we also write a copy of the parametrized helper JS | |
it is re-used in the build report | |
*/ | |
customHelperJs='imageGallery.js' | |
new File("${envVars['SESSIONS_WORKSPACE']}/ASSAY_EXPLORER_$sessionID").mkdir() | |
output=new File("${envVars['SESSIONS_WORKSPACE']}/ASSAY_EXPLORER_$sessionID/$customHelperJs") | |
fileWriter=output.newWriter(false) | |
fileWriter<<helperJavaScript | |
fileWriter.flush() | |
fileWriter.close() | |
imageGalleryHtml= """<script type="text/javascript"> ${helperJavaScript} </script>""" | |
html=""" | |
<input id="fillStrategy" name="value" type="text" class="setting-input " value="" hidden=true> | |
<div id="openseadragon1" style="width: 1200px; height: 720px;"></div> | |
<script src="/userContent/js/$osdJs/openseadragon.min.js"></script> | |
<script src="/userContent/js/openseadragon-filtering.js"></script> | |
<script src="/userContent/js/caman.full.min.js"></script> | |
""" | |
return html+imageGalleryHtml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment