jenkinsci / bitbucket-branch-source-plugin

Bitbucket Branch Source Plugin
https://plugins.jenkins.io/cloudbees-bitbucket-branch-source
MIT License
216 stars 353 forks source link

dsl-testing :: javaposse.jobdsl.dsl.DslScriptException with OrganizationFolder #319

Open pniederlag opened 4 years ago

pniederlag commented 4 years ago

Description

trying to establish testing for our job-dsl scripts we are running into issues with plugin bitbucket-branch-source. Using the job-dsl playground http://job-dsl.herokuapp.com/ with the following snippet we see the very same exception we get in our test-setup.

job-dsl snippet

organizationFolder('foo') {
    displayName('Foobar')

    organizations {
        bitbucket {
            serverUrl('https://stash.foobar.com')
            repoOwner('foo')
            credentialsId('stash-token')

            traits {
                sourceWildcardFilter {
                    includes('sample-project')
                    excludes('')
                }
            }
        }
    }
}

exception

javaposse.jobdsl.dsl.DslScriptException: (script, line 5) No signature of method: javaposse.jobdsl.dsl.helpers.workflow.ScmNavigatorsContext.bitbucket() is applicable for argument types: (script$_run_closure1$_closure2$_closure3) values: [script$_run_closure1$_closure2$_closure3@756dbb50]
jam01 commented 3 years ago

Did you happen to solve this? Seeing the same issue with gitea, and wondering if it might be related.

ludenus commented 3 years ago

same issue here trying to use jenkins helm chart and configure bitbucket organization folder via JCasc jobDSL as described here https://github.com/jenkinsci/configuration-as-code-plugin/blob/master/demos/jobs/bitbucket.yaml

ypyly commented 2 years ago

same issue with github-branch-source - did anyone managed to fix this?

pniederlag commented 2 years ago

we have it working for quite some time... we don't use the trait{} block in bitbucket but instead have some configure { node -> blocks to accomplish the setup.

pniederlag commented 2 years ago

Working Example

#!/usr/bin/env groovy
organizationFolder('example-org-folder') {
    displayName('Org Folder')
    description('automatic Jenkinsfile processing for org folder')
    organizations {
        bitbucket {
            credentialsId('my-credential-id')
            repoOwner('XYZ')
            serverUrl('https://fancy.example.com')
            traits {
              // - nonsense, due to traits with same name in different scopes, see configure block below
            }
        }
    }
    //projectFactories {
    //  workflowMultiBranchProjectFactory {
    //    scriptPath('Jenkinsfile')
    //  }
    //}
    orphanedItemStrategy {
        discardOldItems {
            daysToKeep(7)
            numToKeep(3)
        }
    }
    // discover Branches (workaround due to JENKINS-46202)
    configure { node ->
        // node represents <jenkins.branch.OrganizationFolder>
        def traits = node / 'navigators' / 'com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMNavigator' / 'traits'
        traits << 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait' {
           strategyId(3) // detect all branches
        }
        traits << 'com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait' {
          strategyId(1)
        }
        traits << 'com.cloudbees.jenkins.plugins.bitbucket.TagDiscoveryTrait' {

        }
        traits << 'jenkins.plugins.git.traits.CloneOptionTrait' {
          // we must add something else than only noTags(false) in order to get it working
          'extension'(class: 'hudson.plugins.git.extensions.impl.CloneOption') {
            noTags(false)
            honorRefspec(false)
            timeout("15")
            shallow(false)
            reference("")
            depth(0)
          }
        }

        // Set child scan triggers to 15 minutes
        node / 'properties' << 'jenkins.branch.OrganizationChildTriggersProperty' {
          templates {
            'com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger' {
              spec('H/5 * * * *')
              interval('900000')
            }
          }
        }

        // Add build strategies
        node / 'buildStrategies' << 'jenkins.branch.buildstrategies.basic.AllBranchBuildStrategyImpl' {
          strategies {
            'jenkins.branch.buildstrategies.basic.AnyBranchBuildStrategyImpl' {
              strategies {
                'jenkins.branch.buildstrategies.basic.TagBuildStrategyImpl' {
                  atLeastMillis(-1)
                  atMostMillis(604800000)
                }
                'jenkins.branch.buildstrategies.basic.BranchBuildStrategyImpl' {}
              }
            }
            'jenkins.branch.buildstrategies.basic.SkipInitialBuildOnFirstBranchIndexing' {}
          }
        }
    }
    //properties {
      //organizationChildTriggersProperty {
      //  periodicFolderTrigger {
      //    interval("15m")
      //  }
      //}
    //}
    triggers {
      periodicFolderTrigger {
        interval("1d")
      }
    }
}
gentitope commented 1 year ago

@pniederlag i tried this option with my script but not able to run the script with the error below:

2023-02-08 11:56:37.934+0000 [id=32]    WARNING j.util.groovy.GroovyHookScript#execute: Failed to run script file:/var/jenkins_home/init.groovy.d/..2023_02_08_11_55_34.519861074/init0.groovy
groovy.lang.MissingMethodException: No signature of method: init0.organizationFolder() is applicable for argument types: (java.lang.String, init0$_run_closure1) values: [orderbird, init0$_run_closure1@5bca9a44]
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:71)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:80)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:157)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:177)
    at init0.run(init0.groovy:2)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:574)
    at jenkins.util.groovy.GroovyHookScript.execute(GroovyHookScript.java:136)
    at jenkins.util.groovy.GroovyHookScript.execute(GroovyHookScript.java:126)
    at jenkins.util.groovy.GroovyHookScript.run(GroovyHookScript.java:109)
    at hudson.init.impl.GroovyInitScript.init(GroovyInitScript.java:42)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:109)
    at hudson.init.TaskMethodFinder$TaskImpl.run(TaskMethodFinder.java:185)
    at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:305)
    at jenkins.model.Jenkins$5.runTask(Jenkins.java:1161)
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:221)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:120)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:70)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)
nfalco79 commented 1 week ago

Not clear if the plugin is the guilty of the failure anyway @pniederlag can I close the issue if as the example in configuration-as-code-plugin repository works?

pniederlag commented 1 week ago

Workaround ist working for us. I suspect there is still some glitch in the code when I read the comments of the other users. However currently I am not able to put time into this to check wether it's working or still breaking.