@Override public Object getValue(CpsScript script) throws Exception { Binding binding = script.getBinding(); Object docker; if (binding.hasVariable(getName())) { docker = binding.getVariable(getName()); } else { // Note that if this were a method rather than a constructor, we would need to mark it @NonCPS lest it throw CpsCallableInvocation. docker = script.getClass().getClassLoader().loadClass("org.jenkinsci.plugins.docker.workflow.Docker").getConstructor(CpsScript.class).newInstance(script); binding.setVariable(getName(), docker); } return docker; }
@Nonnull @Override public Object getValue(CpsScript script) throws Exception { Binding binding = script.getBinding(); Object kubernetes; if (binding.hasVariable(getName())) { kubernetes = binding.getVariable(getName()); } else { // Note that if this were a method rather than a constructor, we would need to mark it @NonCPS lest it throw CpsCallableInvocation. kubernetes = script.getClass().getClassLoader().loadClass("io.fabric8.kubernetes.pipeline.Kubernetes").getConstructor(CpsScript.class).newInstance(script); binding.setVariable(getName(), kubernetes); } return kubernetes; }
@Nonnull @Override public Object getValue(CpsScript script) throws Exception { Binding binding = script.getBinding(); Object kubernetes; if (binding.hasVariable(getName())) { kubernetes = binding.getVariable(getName()); } else { // Note that if this were a method rather than a constructor, we would need to mark it @NonCPS lest it throw CpsCallableInvocation. kubernetes = CubeDSL.class.getClassLoader().loadClass("io.fabric8.kubernetes.pipeline.arquillian.cube.kubernetes.Cube").getConstructor(CpsScript.class).newInstance(script); binding.setVariable(getName(), kubernetes); } return kubernetes; }
@Nonnull @Override public Object getValue(CpsScript script) throws Exception { Binding binding = script.getBinding(); Object kubernetes; if (binding.hasVariable(getName())) { kubernetes = binding.getVariable(getName()); } else { // Note that if this were a method rather than a constructor, we would need to mark it @NonCPS lest it throw CpsCallableInvocation. kubernetes = CubeDSL.class.getClassLoader().loadClass("io.fabric8.kubernetes.pipeline.arquillian.cube.kubernetes.Cube").getConstructor(CpsScript.class).newInstance(script); binding.setVariable(getName(), kubernetes); } return kubernetes; }
@SuppressWarnings("unchecked") // Binding final void $initialize() throws IOException { // TODO JENKINS-33353 could make this a GlobalVariable instead getBinding().setVariable(STEPS_VAR, new DSL(execution.getOwner())); }
@Nonnull @Override public Object getValue(@Nonnull CpsScript script) throws Exception { Binding binding = script.getBinding(); script.println(); Object openshift; if (binding.hasVariable(getName())) { openshift = binding.getVariable(getName()); } else { // Note that if this were a method rather than a constructor, we // would need to mark it @NonCPS lest it throw // CpsCallableInvocation. openshift = script.getClass().getClassLoader() .loadClass("com.openshift.jenkins.plugins.OpenShiftDSL") .getConstructor(CpsScript.class).newInstance(script); binding.setVariable(getName(), openshift); } return openshift; } }
@Override public Object getValue(CpsScript script) throws Exception { Binding binding = script.getBinding(); CpsThread c = CpsThread.current(); if (c == null) throw new IllegalStateException("Expected to be called from CpsThread"); ClassLoader cl = getClass().getClassLoader(); String scriptPath = "dsl/" + getFunctionName() + ".groovy"; Reader r = new InputStreamReader(cl.getResourceAsStream(scriptPath), "UTF-8"); GroovyCodeSource gsc = new GroovyCodeSource(r, getFunctionName() + ".groovy", cl.getResource(scriptPath).getFile()); gsc.setCachable(true); Object pipelineDSL = c.getExecution() .getShell() .getClassLoader() .parseClass(gsc) .newInstance(); binding.setVariable(getName(), pipelineDSL); r.close(); return pipelineDSL; }
@Nonnull @Override public Object getValue(@Nonnull CpsScript cpsScript) throws Exception { Binding binding = cpsScript.getBinding(); Object artifactory; if (binding.hasVariable(getName())) { artifactory = binding.getVariable(getName()); } else { artifactory = new ArtifactoryPipelineGlobal(cpsScript); binding.setVariable(getName(), artifactory); } return artifactory; } }
if (getBinding().hasVariable(name)){ Object o = getBinding().getVariable(name); if (!InvokerHelper.getMetaClass(o).respondsTo(o, "call", (Object[]) args).isEmpty()){ try{ DSL dsl = (DSL) getBinding().getVariable(STEPS_VAR); return dsl.invokeMethod(name,args);
@Nonnull @Override public Object getValue(@Nonnull CpsScript script) throws Exception { Binding binding = script.getBinding(); Object instance; if (binding.hasVariable(getName())) { instance = binding.getVariable(getName()); } else { CpsThread c = CpsThread.current(); if (c==null) throw new IllegalStateException("Expected to be called from CpsThread"); instance = c.getExecution().getShell().getClassLoader().loadClass(getName()).newInstance(); /* We could also skip registration of vars in GroovyShellDecoratorImpl and use: instance = c.getExecution().getShell().parse(source(".groovy")); But then the source will appear in CpsFlowExecution.loadedScripts and be offered up for ReplayAction. We might *want* to support replay of global vars & classes at some point, but to make it actually work we would also need to start calling LoadStepExecution.Replacer. */ binding.setVariable(getName(), instance); } return instance; }