Thank you Daniel.  That worked perfectly.

Now I'm trying to figure out how to add a BooleanParameterDefinition and a
single step conditional builder, keying off that boolean, to execute the
shell script.


On Tue, Dec 10, 2013 at 2:35 PM, Daniel Beck <m...@beckweb.net> wrote:

> Use getBuildersList instead. The following works for me in the Script
> Console:
>
>         def i = Jenkins.instance.getItemByFullName("foo") // might be
> different from yours
>         def l = i.buildersList
>         def oldBuilders = l.toList()
>         l.clear()
>         l.add(new hudson.tasks.Shell("echo 'Hello World'"))
>         l.addAll(oldBuilders)
>         i.save()
>
> On 10.12.2013, at 19:56, Steve Maring <steve.mar...@gmail.com> wrote:
>
> > I have hundreds of Jobs that I would like to programmatically add an
> initial build step to using the Build Flow Plugin
> >
> > When I try something like this ...
> >
> >         String jobName = "MY_JOB";
> >       List<TopLevelItem> topLevelItems =
> Jenkins.getInstance().getAllItems(TopLevelItem.class);
> >       Job job;
> >       Iterator<TopLevelItem> topLevelItemsIterator =
> topLevelItems.iterator();
> >       while (topLevelItemsIterator.hasNext()) {
> >               TopLevelItem topLevelItem = topLevelItemsIterator.next();
> >               Collection<? extends Job> jobs = topLevelItem.getAllJobs();
> >               job = (jobs.toArray())[0];
> >               if (job.getName().equals(jobName)) {
> >                       break;
> >               } else {
> >                       job = null;
> >           }
> >       }
> >       FreeStyleProject project = (FreeStyleProject) job;
> >       List<Builder> builders = project.getBuilders();
> >       Shell propertyVersionsCommand = new Shell("echo 'Hello World'");
> >       builders.add(0, propertyVersionsCommand);
> >
> >
> > I get ...
> >
> > ERROR: Failed to run DSL Script
> >
> > java.lang.UnsupportedOperationException
> >
> >       at
> java.util.Collections$UnmodifiableList.add(Collections.java:1216)
> >
> >       at java_util_List$add$0.call(Unknown Source)
> >       at
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
> >       at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
> >       at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
> >       at Script1.setPropertyVersions(Script1.groovy:227)
> >       at Script1$setPropertyVersions.callCurrent(Unknown Source)
> >       at
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
> >       at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
> >       at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
> >       at Script1.run(Script1.groovy:193)
> >       at Script1$run.call(Unknown Source)
> >       at
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
> >       at Script1$run.call(Unknown Source)
> >       at
> com.cloudbees.plugins.flow.FlowDSL.executeFlowScript(FlowDSL.groovy:82)
> >
> >
> >
> > Under "Project-based Matrix Authorization Strategy" I've confirmed that
> I have EVERY perm possible checked there.
> >
> > What am I missing?
> >
> > -Steve
> > Orlando, FL
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Jenkins Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to jenkinsci-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/groups/opt_out.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Jenkins Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/jenkinsci-users/w4i_gpsbKKg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> jenkinsci-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to