jenkinsci / configuration-as-code-plugin

Jenkins Configuration as Code Plugin
https://plugins.jenkins.io/configuration-as-code
MIT License
2.68k stars 718 forks source link

Error when applying the job DSL configuration extracted from your bitbucket example #1211

Closed ZeBidule closed 4 years ago

ZeBidule commented 4 years ago

Description

Got groovy.lang.MissingMethodException: No signature of method (see stack trace attached: error_casc.log) when applying the following job DSL configuration extracted from your bitbucket example :

jobs:
  - script: >
      organizationFolder('Bitbucket Organization Folder') {
        description("Bitbucket orga folder configured with JCasC")
        displayName('My Project')
        organizations {
          bitbucket {
            serverUrl("https:BITBUCKET_URL")
            repoOwner("OWN")
            credentialsId("bitbucket-http")
            traits {
              submoduleOptionTrait {
                extension {
                  recursiveSubmodules(true)
                }
              }
            }
          }
        }
      } 
jetersen commented 4 years ago

Don't use > it becomes one long string. Use | a literal block

jetersen commented 4 years ago

Also this seems more like a Job DSL issue 😓

jetersen commented 4 years ago

I'd suggest using file or url block instead

jobs:
  - file: /src/jobdsl/organisations.groovy
ZeBidule commented 4 years ago

OK thanks for your really quick answers :)

ZeBidule commented 4 years ago

I have tried the both solutions and i still have the same error :

groovy.lang.MissingMethodException: No signature of method: javaposse.jobdsl.plugin.structs.DescribableContext.traits() is applicable for argument types: (script$_run_closure1$_closure2$_closure3$_closure4) values: [script$_run_closure1$_closure2$_closure3$_closure4@39a9c913]
jetersen commented 4 years ago

Downgrade cloudbees-bitbucket-branch-source to something before 2.6.0 😓

ZeBidule commented 4 years ago

OK, i try the downgrade...

I manage to avoid the error by removing the traits section and replacing it with the none declarative-compatible syntax but I doesn't work for the recursiveSubmodules option :

jobs:
  - script: >
      organizationFolder('Bitbucket Organization Folder') {
        description("Bitbucket orga folder configured with JCasC")
        displayName('My Project')
        organizations {
          bitbucket {
            serverUrl("https://$BITBUCKET_URL")
            repoOwner("OWN")
            credentialsId("bitbucket-http")
          }
        }
        // "Traits" ("Behaviours" in the GUI) that are NOT "declarative-compatible"
        // For some 'traits, we need to configure this stuff by hand until JobDSL handles it
        // https://issues.jenkins.io/browse/JENKINS-45504
        configure { node ->
            def traits = node / navigators / 'com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMNavigator' / traits
            traits << 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait' {
                strategyId('3')
            }
            traits << 'com.cloudbees.jenkins.plugins.bitbucket.SSHCheckoutTrait' {
                credentialsId('bitbucket-ssh')
            }
            traits << 'jenkins.scm.impl.trait.WildcardSCMSourceFilterTrait' {
                includes('myjob')
                excludes('')
            }
            traits << 'com.cloudbees.jenkins.plugins.bitbucket.WebhookRegistrationTrait' {
                mode('ITEM')
            }
            traits << 'jenkins.plugins.git.traits.SubmoduleOptionTrait' {
                extension << 'hudson.plugins.git.extensions.impl.SubmoduleOption' {
                    recursiveSubmodules('true')
                }
            }
        }
ZeBidule commented 4 years ago

Ok the declarative-compatible traits syntax works with cloudbees-bitbucket-branch-source version 2.5.0 so the regression appeared in version 2.6.0. Sorry for the inconvenience, I just figure out that an issue was already created in their repository : https://github.com/jenkinsci/bitbucket-branch-source-plugin/issues/258

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

jetersen commented 4 years ago

Should be fixed in recent version of cloudbees-bitbucket-branch-source https://github.com/jenkinsci/bitbucket-branch-source-plugin/releases/tag/cloudbees-bitbucket-branch-source-2.7.0