[JIRA] (JENKINS-39682) Generated Mutlibranch Pipeline Job does not index branches

17 views
Skip to first unread message

pwolf@cloudbees.com (JIRA)

unread,
Nov 11, 2016, 4:28:01 PM11/11/16
to jenkinsc...@googlegroups.com
Patrick Wolf created an issue
 
Jenkins / Bug JENKINS-39682
Generated Mutlibranch Pipeline Job does not index branches
Issue Type: Bug Bug
Assignee: Daniel Spilker
Components: job-dsl-plugin
Created: 2016/Nov/11 9:27 PM
Priority: Minor Minor
Reporter: Patrick Wolf

Using a JobDSL script to generate a multibranch Pipeline job does not trigger a branch index to find Jenkinsfile

Here is a simple dsl job

multibranchPipelineJob(repo) {
  branchSources {
    github {
      scanCredentialsId(credentials)
      repoOwner(credentials)
      repository(repo)
    }
  }
}

Using this created the job fine but did not trigger a branch scan until I manually triggered a branch index. It also works if you open the multibranch job configuration and save it with no changes.

Creating a multibranch job directly from the UI works fine.

The only way I can trigger a branch index is to add a triggers section to the command to periodically scan every minute. I then had to create 3 build steps:

1. JobDSL to create mutlibranch Pipeline job with a trigger set to 1 minute
2. Shell step to Sleep for 60 seconds
3. JobDSL to modify the multibranch Pipeline job and turn off the trigger.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

pwolf@cloudbees.com (JIRA)

unread,
Nov 14, 2016, 11:35:01 AM11/14/16
to jenkinsc...@googlegroups.com
Patrick Wolf commented on Bug JENKINS-39682
 
Re: Generated Mutlibranch Pipeline Job does not index branches

per Jesse Glick: probably `job-dsl` should be enhanced to ensure that for a `ComputedFolder` it automatically calls `scheduleBuild` after creation

jglick@cloudbees.com (JIRA)

unread,
Nov 15, 2016, 9:15:04 AM11/15/16
to jenkinsc...@googlegroups.com

mail@daniel-spilker.com (JIRA)

unread,
Nov 16, 2016, 3:10:01 AM11/16/16
to jenkinsc...@googlegroups.com
Daniel Spilker assigned an issue to Unassigned
Change By: Daniel Spilker
Assignee: Daniel Spilker

mail@daniel-spilker.com (JIRA)

unread,
Nov 16, 2016, 3:10:01 AM11/16/16
to jenkinsc...@googlegroups.com
Daniel Spilker updated an issue

Job DSL uses standard Jenkins API to create jobs, specifically Jenkins#createProjectFromXML(String name, InputStream xml). If the job does not trigger after creating from Job DSL, it will probably also not trigger after creating through CLI or REST API which use the same API internally. This should not be fixed at the consumer side of the API. It needs either to be fixed in core or in Multibranch Pipeline plugin.

Change By: Daniel Spilker
Component/s: core
Component/s: workflow-multibranch-plugin

stephen.alan.connolly@gmail.com (JIRA)

unread,
Mar 1, 2017, 5:06:01 AM3/1/17
to jenkinsc...@googlegroups.com
Stephen Connolly updated an issue
Change By: Stephen Connolly
Labels: multibranch scm-api-tidy-scrub

jglick@cloudbees.com (JIRA)

unread,
Mar 3, 2017, 2:31:01 PM3/3/17
to jenkinsc...@googlegroups.com
Jesse Glick updated an issue
Change By: Jesse Glick
Component/s: cloudbees-folder-plugin
Component/s: core
Component/s: workflow-multibranch-plugin

paul.mccrady@gmail.com (JIRA)

unread,
Mar 21, 2018, 6:16:03 AM3/21/18
to jenkinsc...@googlegroups.com
Paul McCrady commented on Bug JENKINS-39682
 
Re: Generated Mutlibranch Pipeline Job does not index branches

Are there any plans to address this issue?

This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

mail@daniel-spilker.com (JIRA)

unread,
Jun 21, 2018, 12:01:05 PM6/21/18
to jenkinsc...@googlegroups.com
Daniel Spilker resolved as Fixed
 

A unique id has to be assigned to each branch source, otherwise indexing does not work as expected.

multibranchPipelineJob('example') {
  branchSources {
    github {
      id('3948734')
      scanCredentialsId('github')
      repoOwner('jenkinsci')
      repository('job-dsl-plugin')
    }
  }
}
Change By: Daniel Spilker
Status: Open Resolved
Assignee: Daniel Spilker
Resolution: Fixed

mail@daniel-spilker.com (JIRA)

unread,
Jun 21, 2018, 12:21:02 PM6/21/18
to jenkinsc...@googlegroups.com
Daniel Spilker reopened an issue
 

Ah, ignore my last comment. I could reproduce the problem.

Change By: Daniel Spilker
Resolution: Fixed
Status: Resolved Reopened

jenkins@rfc805.net (JIRA)

unread,
May 1, 2019, 11:46:05 AM5/1/19
to jenkinsc...@googlegroups.com
John F commented on Bug JENKINS-39682
 
Re: Generated Mutlibranch Pipeline Job does not index branches

I'm having an issue that matches this with Bitbucket multi branch pipeline jobs created from the Job DSL.  The credentials seem to be invalid, even though they are set correctly.  After running the seed job, the indexing will fail with an authorization failure against Bitbucket.  If I simply open the configuration for the job in the web UI, and save it with no changes, it will work from that point forward.  It also shows a red failure icon with "Not found" for the Owner (Project in BB) until I hit save.  Is this the same issue?  It's unclear from the comments/lack of resolution.  Are there possibly other already known issues that match this?

This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

gregoire.waymel@decathlon.com (JIRA)

unread,
Jun 14, 2019, 6:42:03 AM6/14/19
to jenkinsc...@googlegroups.com

I also faced this issue. I end up adding a build step on my job :

 1st step: Creation of the pipeline if it do not exist:

hudson.model.Item i=jenkins.model.Jenkins.instance.getItemByFullName("$folder/$name")

if (i!=null){
   throw new javaposse.jobdsl.dsl.DslException("$folder/$name already exist")
}

multibranchPipelineJob("$folder/$name") {
  description("")
  ...
  branchSources {
    branchSource {
      source {
        github {
          id(UUID.randomUUID().toString())
          ...
        }
      }
      strategy {
        ...
      }
    }
  }

  factory {
    workflowBranchProjectFactory {
      scriptPath("Jenkinsfile")
    }
  }
}

Then on another step, I execute the post action that are not triggered :

println("Initializing job")

hudson.model.Item i=jenkins.model.Jenkins.instance.getItemByFullName("$folder/$name")

println("Job found: "+i.getDisplayName())

i.save()
i.getSCMSources().get(0).afterSave()

queue("$folder/$name")

println("Inializing done")

I save the job (I'm not sure it is needed, but it make the configuration file much like it is if I do it manually) then I trigger the "afterSave()" method on the SCM source (In github use-case, it adds the Webhook on the repo ) and finally I trigger a build of the multibranch so that branch are scanned.

JobDSL is generic, so I'm not sure one day it will be able to do that, but until then, this will do the trick .... I hope ...

mail@daniel-spilker.com (JIRA)

unread,
Jun 14, 2019, 8:52:02 AM6/14/19
to jenkinsc...@googlegroups.com

mail@daniel-spilker.com (JIRA)

unread,
Jun 14, 2019, 8:59:02 AM6/14/19
to jenkinsc...@googlegroups.com
Daniel Spilker commented on Bug JENKINS-39682
 
Re: Generated Mutlibranch Pipeline Job does not index branches

The problem is IMHO, that the MultiBranchProject will do the necessary updates only after the config page has been saved (Stapler submit):

https://github.com/jenkinsci/branch-api-plugin/blob/branch-api-2.5.2/src/main/java/jenkins/branch/MultiBranchProject.java#L896-L897

But it should also implement ItemListener and do the updates in onUpdated, onCreated, etc to allow to create a multi-branch project through API (e.g. ModifiableTopLevelItemGroup.createProjectFromXML or AbstractItem.updateByXml).

This issue does not only apply to Job DSL, but also to other consumers of that API, maybe CLI and REST API.

mail@daniel-spilker.com (JIRA)

unread,
Jun 14, 2019, 9:00:08 AM6/14/19
to jenkinsc...@googlegroups.com
Daniel Spilker assigned an issue to Stephen Connolly
 
Change By: Daniel Spilker
Assignee: Daniel Spilker Stephen Connolly

mail@daniel-spilker.com (JIRA)

unread,
Jun 14, 2019, 11:04:03 AM6/14/19
to jenkinsc...@googlegroups.com

rene.scheibe@gmail.com (JIRA)

unread,
Jun 14, 2019, 12:22:02 PM6/14/19
to jenkinsc...@googlegroups.com

rene.scheibe@gmail.com (JIRA)

unread,
Jun 14, 2019, 12:23:03 PM6/14/19
to jenkinsc...@googlegroups.com
René Scheibe edited a comment on Bug JENKINS-39682
[~daspilker] does this pull request also fix the issues reported in JENKINS-43693 and JENKINS-57235? At first sight it might do so. This would be really great.

rene.scheibe@gmail.com (JIRA)

unread,
Jun 14, 2019, 12:23:06 PM6/14/19
to jenkinsc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages