• Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • job-dsl-plugin
    • None

      I have a seed job with an input parameter named owner and want to pass its value into a Bitbucket Branch Source Plugin job like this:

      organizationFolder('${owner}') {
        organizations {
          bitbucket {
            serverUrl('https://git.mycompany.com')
            repoOwner('myproject')
            credentialsId('bitbucket-user')
          }
        }
      }

      The script above works. Then I replace myproject with ${owner} and I get this error:

      hudson.model.Failure: '$' is an unsafe character
      	at jenkins.model.Jenkins.checkGoodName(Jenkins.java:3998)
      	at javaposse.jobdsl.plugin.JenkinsJobManagement.createOrUpdateConfig(JenkinsJobManagement.java:138)

      I also tried with double quotes, hoping that the variable would be resolved as a GString, but then I get:

      FATAL: null
      java.lang.StackOverflowError
      	at sun.reflect.GeneratedMethodAccessor2477.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
      	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
      	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
      	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
      	at javaposse.jobdsl.dsl.ContextHelper.executeInContext(ContextHelper.groovy:16)

      Is this an issue with the job dsl plugin or the Bitbucket branch source plugin?

          [JENKINS-63083] Environment variable doesn't resolve

          Jesse Glick added a comment -

          matfau looks like you had a little problem with Jira! Can you please close your duplicates?

          Jesse Glick added a comment - matfau looks like you had a little problem with Jira! Can you please close your duplicates?

          Mats Faugli added a comment -

          jglick Yeah, I had trouble creating the ticket at the time so I must have tried several times, and I wasn't even aware that any of them got created. Looks like I don't have the correct permission to close those duplicates, is that something you can help me with?

          Anyway, I found a workaround by referring to the variable like this:

          repoOwner(binding.variables.owner)
          

          Mats Faugli added a comment - jglick Yeah, I had trouble creating the ticket at the time so I must have tried several times, and I wasn't even aware that any of them got created. Looks like I don't have the correct permission to close those duplicates, is that something you can help me with? Anyway, I found a workaround by referring to the variable like this: repoOwner(binding.variables.owner)

          Jesse Glick added a comment -

          I am afraid I also lack permission to close the duplicates.

          Jesse Glick added a comment - I am afraid I also lack permission to close the duplicates.

          See https://groovy-lang.org/syntax.html#_string_interpolation.

          If you want the string as it is, there is no need for interpolation. This works for me:

          organizationFolder(owner) {
            organizations {
              bitbucket {
                serverUrl('https://git.mycompany.com')
                repoOwner('myproject')
                credentialsId('bitbucket-user')
              }
            }
          }
          

          Please note that owner is a special variable within Groovy closures. It's a property of groovy.lang.Closure. Depending on the context, the variable may resolve to that property instead of the build parameter.

          Daniel Spilker added a comment - See https://groovy-lang.org/syntax.html#_string_interpolation . If you want the string as it is, there is no need for interpolation. This works for me: organizationFolder(owner) { organizations { bitbucket { serverUrl( 'https: //git.mycompany.com' ) repoOwner( 'myproject' ) credentialsId( 'bitbucket-user' ) } } } Please note that owner is a special variable within Groovy closures. It's a property of groovy.lang.Closure . Depending on the context, the variable may resolve to that property instead of the build parameter.

            matfau Mats Faugli
            matfau Mats Faugli
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: