ghale / gradle-jenkins-plugin

Gradle plugin to programmatically configure Jenkins jobs.
123 stars 42 forks source link

MissingMethodException when specifying Git branch #61

Closed watchwithmike closed 9 years ago

watchwithmike commented 9 years ago

I'm getting a "No signature of method" exception when I'm attempting to use the DSL to set branch on a github repository. The way the DSL is configured I need to use a 'remote' closure to specify credentials which gets me the following job definition:

job("my-core") {
    logRotator(-1, 20, -1, -1)
    scm {
        git {
            branch('origin/master')
            remote {
                github('myco/my-core', 'https')
                credentials('buildcreds')
            }
        }
    }
}

If I run that on the Job DSL Playground I get the XML I'm looking for. When I use this DSL in my Gradle Jenkins job I get the following exception:

Caused by: groovy.lang.MissingMethodException: No signature of method: java.lang.String.call() is applicable for argument types: (java.lang.String) values: [origin/master]
Possible solutions: wait(), any(), wait(long), split(java.lang.String), take(int), count(java.lang.String)
...
    at javaposse.jobdsl.dsl.ContextHelper.executeInContext(ContextHelper.groovy:14)
  1. Is there something obvious I'm missing?
  2. Is there a way to swap the version of the Job DSL being used? (I swear I saw this documented somewhere but I'm unable to find it again).

Thanks, Mike

watchwithmike commented 9 years ago

In answer to my second question, I believe I was able to swap out the job-dsl-core with 1.35 (latest version available in the repository) and I'm getting the same results. The buildscript block I used to swap out the core was:

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
        maven {
            url('http://repo.jenkins-ci.org/releases/')
        }
    }
    dependencies {
        classpath("com.terrafolio:gradle-jenkins-plugin:1.3.1") {
            exclude group: 'org.jenkins-ci.plugins', module:'job-dsl-core'
        }
        classpath 'org.jenkins-ci.plugins:job-dsl-core:1.35'
    }
}

apply plugin: 'com.terrafolio.jenkins'
watchwithmike commented 9 years ago

Just in case I'm missing the bigger picture somewhere else, here is a complete build.gradle that causes the failure.

plugins {
    id 'com.terrafolio.jenkins' version '1.3.1'
}
apply plugin: 'com.terrafolio.jenkins'

jenkins {
    servers {
        local {
            url 'http://localhost:8080'
            username ''
            password ''
        }
    }

    defaultServer servers.local

    def branches = ['master', 'develop']

    dsl {
        branches.each { branch ->
            job("my-core ${branch.toUpperCase()}") {
                scm {
                    git {
                        remote {
                            github('myco/my-core', 'https')
                            credentials('mycreds')
                        }
                        branch("origin/${branch}")
                    }
                }
            }
        }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}
ghale commented 9 years ago

I think it's a conflict on the closure parameter { branch -> and the branch() method on the git dsl object. If you change the parameter to something else (e.g. { theBranch ->), it should work.

watchwithmike commented 9 years ago

That was exactly it! Thanks for the quick response, much obliged.