Jenkins Job DSL Organisation folder - Not able to use sshCheckoutTrait()

39 Views Asked by At

As per the JobDSL library documentation, We have a sshCheckoutTrait() found under OrganisationFolder > organizations > gitlab > traits > sshCheckoutTrait

My JobDSL pipeline looks like this

organizationFolder('jobDsls/myOrgFolder') {
    displayName('OrgFolder Job')
    description('Org folder via JobDsl')
    organizations {
        gitlab {
            serverName("gitlab-connection")
            credentialsId('gitlab-creds')
            projectOwner('cloud-native')
            traits {
                sourceWildcardFilter {
                    includes('*')
                    excludes('')
                }
                sshCheckoutTrait {
                    credentialsId('gitlab-creds')
                }
                ...
            }
        }
    }
    projectFactories {
        workflowMultiBranchProjectFactory {
            scriptPath("Jenkinsfile")
        }
    }
}

But while creating the JobDSL, this errors out on the following:

ERROR: Found multiple extensions which provide method sshCheckoutTrait with arguments [organisationFolder$_run_closure1$_closure2$_closure10$_closure11$_closure13@4483ccd0]: [[com.cloudbees.jenkins.plugins.bitbucket.SSHCheckoutTrait, io.jenkins.plugins.gitlabbranchsource.SSHCheckoutTrait, org.jenkinsci.plugins.github_branch_source.SSHCheckoutTrait]]

I even tried with the configure() block as follows

organizationFolder('jobDsls/myOrgFolder') {
    displayName('OrgFolder Job')
    description('Org folder via JobDsl')
    organizations {
        gitlab {
            serverName("gitlab-connection")
            credentialsId('gitlab-creds')
            projectOwner('cloud-native')
            traits {
                sourceWildcardFilter {
                    includes('*')
                    excludes('')
                }
            }
        }
        configure {
            def traits = it / navigators / 'io.jenkins.plugins.gitlabbranchsource.GitLabSCMNavigator' / traits
            traits << 'io.jenkins.plugins.gitlabbranchsource.SSHCheckoutTrait' {
                credentialsId('gitlab-creds')
            }
        }
    }
    projectFactories {
        workflowMultiBranchProjectFactory {
            scriptPath("Jenkinsfile")
        }
    }
}

This actually worked but not as expected. It created a SshCheckout field in pipeline, but not at the expected location, due to which organisationFolder is not able to scan repos via ssh. Can anyone help with the solution? Thanks

0

There are 0 best solutions below