This snippet was very helpful, however after I call job.save() I notice the
change is not reflected in the UI.  I know the code worked because when
open the configuration of the upstream job, I do see the change in the
"build other projects" text field.   But it doesn't appear in the
"Downstream projects" list of that project's page.

Any ideas?

On Wed, Jun 6, 2012 at 3:03 AM, HARDION Vincent <
[email protected]> wrote:

> Hi,
>
> This snippet could help you :
>
>  def updateJobBuildTrigger(upstreamArtifactId, job, jobname){
>
>    if (job != null){
>
>      def pl = job.publishersList
>      def bt = pl.get(hudson.tasks.BuildTrigger.class)
>      def triggeredJob = bt?.childProjectsValue ?: ""
>      // Recreate the new value of BuildTrigger
>      if(!triggeredJob.contains(jobname)){
>
>        // BuildTrigger is immutable
>        if(!bt){
>          pl.remove( bt)
>        }
>        if(triggeredJob){
>          triggeredJob += ","
>        }
>        triggeredJob += jobname
>
>        pl.add( new hudson.tasks.BuildTrigger(triggeredJob, false))
>        Logger.debug("new triggeredJob = $triggeredJob")
>        job.save()
>      }else{
>        Logger.debug("triggeredJob already contains $jobname")
>      }
>      //        println "[DEBUG] ---> now ${upstreamjob.name} will trigger
> these jobs :
> "+upstreamjob.publishersList.get(hudson.tasks.BuildTrigger.class).childProjectsValue
>    }else{
>      Logger.warning("no hudson job corresponding to ${upstreamArtifactId}
> (dependency of ${jobname})")
>    }
>  }
>
> Best regards,
>
> Vincent
> ________________________________
> From: [email protected] [[email protected]]
> on behalf of Carlton Brown [[email protected]]
> Sent: Tuesday, June 05, 2012 8:05 PM
> To: [email protected]
> Subject: Using Groovy to manipulate the dependency graph
>
> I'm trying to use Groovy to auto-generate Jenkins projects that are
> chained together.    I'd like to use Groovy to set the "build-after" or
> "build-before" list, but it's not obvious to me how to accomplish this in
> the model.    Could anyone clue me in?
>

Reply via email to