Unable to configure Fork Change Request Trait using Job DSL

166 views
Skip to first unread message

Parichay Barpanda

unread,
Aug 16, 2019, 9:11:16 AM8/16/19
to Jenkins Developers
Hi all,

I am trying to configure GitLab Branch Source Plugin organizational folder using Job DSL. But unfortunately job dsl api viewer doesn't detect Fork Merge Request Trait. All the detected traits in Job dsl api viewer takes either int/boolean/string values. But in Fork Merge Request Trait the trust field takes an SCMHeadAuthority object. How does one configure Job DSL with fork `change request` trait for any of the branch source plugin?

Can someone help me with figuring out what is wrong here. I have the following cases:

1. Job DSL doesn't support Fork Merge Request Trait.

2. There is something wrong with the impl of Fork Merge Request Trait.

3. Our Job DSL configuration is incorrect (note unable to configure fork merge request in this configuration):

organizationFolder(name) {
      organizations
{
        displayName
(config.displayName)
        description
(orgDescription)
        gitLabSCMNavigator
{
          projectOwner
(config.group)
          credentialsId
('gitlab_ssh_key')
          serverName
('git.3shape.local')
          traits
{
            subGroupProjectDiscoveryTrait
() // discover projects inside subgroups
            gitLabBranchDiscovery
{
              strategyId
(3) // discover all branches
           
}
            originMergeRequestDiscoveryTrait
{
              strategyId
(1) // discover MRs and merge them with target branch
           
}
            gitLabTagDiscovery
() // discover tags
            gitLFSPullTrait
()
         
}
       
}
     
}
      orphanedItemStrategy
{
        discardOldItems
{
          daysToKeep
(7)
          numToKeep
(10)
       
}
     
}
     
if (!isSandbox()) {
        triggers
{
          periodicFolderTrigger
{
            interval
('1d')
         
}
       
}
     
}
      projectFactories
{
        workflowMultiBranchProjectFactory
{
          scriptPath
('Jenkinsfile')
       
}
     
}
   
}

4. or something else?

Thanks and Regards,
Parichay

Jesse Glick

unread,
Aug 16, 2019, 10:37:32 AM8/16/19
to Jenkins Dev
On Fri, Aug 16, 2019 at 9:11 AM Parichay Barpanda
<parichay...@gmail.com> wrote:
> All the detected traits in Job dsl api viewer takes either int/boolean/string values. But in Fork Merge Request Trait the trust field takes an SCMHeadAuthority object. How does one configure Job DSL with fork `change request` trait for any of the branch source plugin?

I presume like any other `Describable`: you need to pick an
implementation with a `@Symbol`, like

https://github.com/jenkinsci/gitlab-branch-source-plugin/blob/c0c8236ff87b9bc48110690de8eba99a10966e81/src/main/java/io/jenkins/plugins/gitlabbranchsource/ForkMergeRequestDiscoveryTrait.java#L230

Parichay Barpanda

unread,
Aug 16, 2019, 11:03:13 AM8/16/19
to Jenkins Developers
Can you tell how to do it? We are unable to find the configuration in the api viewer.

Thanks.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr1UjomXq8GKBa0GDsHcCPVMswTGUO64csqDCfC0mVadYw%40mail.gmail.com.

Jesse Glick

unread,
Aug 16, 2019, 12:41:04 PM8/16/19
to Jenkins Dev
On Fri, Aug 16, 2019 at 11:03 AM Parichay Barpanda
<parichay...@gmail.com> wrote:
> Can you tell how to do it? We are unable to find the configuration in the api viewer.

Sounds like a question for the users’ list which perhaps the `job-dsl`
maintainer(s) could answer.

Daniel Spilker

unread,
Aug 17, 2019, 7:39:03 AM8/17/19
to jenkin...@googlegroups.com
Hi Parichay,

the Job DSL script would be this:

organizationFolder('example') {
  organizations {
    gitLabSCMNavigator {
      projectOwner('test')
      traits {
        gitLabForkDiscovery {
          strategyId(42)
          trust {
            gitLabTrustNobody()
          }
        }
      }
    }
  }
}

But the script will fail. The problem is caused by the "trust" constructor parameter of ForkMergeRequestDiscoveryTrait. Job DSL uses the Structs plugin for introspection of Describables. Unfortunately Structs does not handle parameter types with generics except for sub classes of java.util.Collection. So the trait will not be shown in the API viewer.

To check if a class is supported by Structs (and Job DSL), run the following in the Jenkins script console:
org.jenkinsci.plugins.structs.describable.DescribableModel.of(io.jenkins.plugins.gitlabbranchsource.ForkMergeRequestDiscoveryTrait)

The result will be
ForkMergeRequestDiscoveryTrait(strategyId: int, trust: java.lang.UnsupportedOperationException: do not know how to categorize attributes of type jenkins.scm.api.trait.SCMHeadAuthority<? super io.jenkins.plugins.gitlabbranchsource.GitLabSCMSourceRequest, ? extends jenkins.scm.api.mixin.ChangeRequestSCMHead2, ? extends jenkins.scm.api.SCMRevision>)
As a workaround, you can remove the type parameters from the "trust" constructor parameter.

@Jesse: would it be feasible to fallback to the raw type when a parameterized type is detected?

Regards,
Daniel


--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.

Jesse Glick

unread,
Aug 17, 2019, 10:00:55 AM8/17/19
to Jenkins Dev
On Sat, Aug 17, 2019 at 7:39 AM Daniel Spilker <ma...@daniel-spilker.com> wrote:
> @Jesse: would it be feasible to fallback to the raw type when a parameterized type is detected?

Best to discuss in JENKINS-26535 which I am guessing describes the
same problem. Probably not a very difficult bug to fix—easily explored
via unit tests.

Parichay Barpanda

unread,
Aug 19, 2019, 11:39:41 AM8/19/19
to Jenkins Developers
Thanks Daniel. But I didn't understand by what you meant "remove the type parameters". I was able to configure the trait using `configure` block. https://gist.github.com/baymac/f1a2249a0ec7b999c057056937e752a6 
To unsubscribe from this group and stop receiving emails from it, send an email to jenkin...@googlegroups.com.

Daniel Spilker

unread,
Aug 19, 2019, 3:17:45 PM8/19/19
to jenkin...@googlegroups.com
Hi Parichay,

I meant changing the constructor to

public ForkMergeRequestDiscoveryTrait(int strategyId, SCMHeadAuthority trust) {

until Structs plugin supports parameters with parameterized type.

I opened a pull request to add some support for parameterized types to Structs plugin:

I tested the fix with Job DSL. It will enable the DSL syntax from my previous post.

Regards,
Daniel


To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/331dfda5-1c82-45bb-b508-1c3658236444%40googlegroups.com.

Parichay Barpanda

unread,
Aug 19, 2019, 4:08:28 PM8/19/19
to Jenkins Developers
Thanks for clarifying it. Also nice to know a fix is at work. 

Joseph P

unread,
Aug 28, 2019, 8:59:32 PM8/28/19
to Jenkins Developers
Thanks for creating a patch for this 🥰

/Joseph
Reply all
Reply to author
Forward
0 new messages