public @CheckForNull Run<?,?> $buildNoException() { if (execution == null) { // Still inside the WorkflowScript constructor, e.g. because getProperty is being called from a @Field. // In such cases we do not expect to be able to use library variables, so just skip it. return null; } try { return $build(); } catch (IOException x) { LOGGER.log(Level.WARNING, null, x); return null; } }
@Override public void println() { invokeMethod("echo", ""); }
@Override public void print(Object value) { // TODO: handling 'print' correctly requires collapsing multiple adjacent print calls into one Step. println(value); }
@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(@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; } }
if (getBinding().hasVariable(name)){ Object o = getBinding().getVariable(name); if (!InvokerHelper.getMetaClass(o).respondsTo(o, "call", (Object[]) args).isEmpty()){ try{ GlobalVariable v = GlobalVariable.byName(name, $buildNoException()); if (v != null) { try { DSL dsl = (DSL) getBinding().getVariable(STEPS_VAR); return dsl.invokeMethod(name,args);
String property = (String) args[0]; CpsScript script = (CpsScript) receiver; Run<?,?> b = script.$buildNoException(); if (GlobalVariable.byName(property, b) != null) { return true;
@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; }
@Override public Object getProperty(String property) { try { return super.getProperty(property); } catch (MissingPropertyException mpe) { // cf. CpsWhitelist.permitsMethod Run<?,?> b = $buildNoException(); GlobalVariable v = GlobalVariable.byName(property, b); if (v != null) { try { return v.getValue(this); } catch (Exception x) { throw new InvokerInvocationException(x); } } if (b != null) { try { String value = EnvActionImpl.forRun(b).getProperty(property); if (value != null) { return value; } } catch (IOException x) { LOGGER.log(Level.WARNING, null, x); } } throw mpe; } }
@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; }
@Override public void println(Object value) { invokeMethod("echo", String.valueOf(value)); }
@Override public Object getValue(CpsScript script) throws Exception { Run<?,?> build = script.$build(); if (build != null) { return new RunWrapper(build, true); } else { throw new IllegalStateException("no associated build"); } }
@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; }
@Whitelisted public void collect() { Map<String, Object> stepVariables = Maps.newLinkedHashMap(); stepVariables.put("env", this); // Throws CpsCallableInvocation - Must be the last line in this method cpsScript.invokeMethod("collectEnv", stepVariables); }
@Override public EnvActionImpl getValue(CpsScript script) throws Exception { Run<?,?> run = script.$build(); if (run != null) { return EnvActionImpl.forRun(run); } else { throw new IllegalStateException("no associated build"); } } @Restricted(DoNotUse.class)
@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())); }
@Whitelisted public void publishBuildInfo(BuildInfo buildInfo) { Map<String, Object> stepVariables = Maps.newLinkedHashMap(); stepVariables.put(BUILD_INFO, buildInfo); stepVariables.put(SERVER, this); // Throws CpsCallableInvocation - Must be the last line in this method cpsScript.invokeMethod("publishBuildInfo", stepVariables); }
@SuppressWarnings("unchecked") @Override public Object getValue(CpsScript script) throws Exception { Run<?,?> b = script.$build(); if (b == null) { throw new IllegalStateException("cannot find owning build");
@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; }
/** * Effectively overrides {@link DefaultGroovyStaticMethods#sleep(Object, long)} * so that {@code SleepStep} works even in the bare form {@code sleep 5}. * * @see CpsClosure2#sleep(long) */ @Whitelisted public Object sleep(long arg) { return invokeMethod("sleep", arg); }