Search code examples
jenkinsgroovyjenkins-job-dsl

seed-job fails fails to parse build user vars plugin


I have the below code in my Jenkins job (pipeline script):

def user_id = ''
wrap([$class: 'BuildUser']) {
    addBadge text: env.BUILD_USER + ', ' + params.Computer
    user_id = env.BUILD_USER_ID.toLowerCase()
}   

But the code fails in the seed-job with:

javaposse.jobdsl.dsl.DslException: startup failed:
script: 106: unexpected token: class
       wrap([$class: 'BuildUser']) {
              ^

1 error

I've found this suggestion but then groovy syntax throws error of: unexpected char : '\'

Any idea how to solve this?


Solution

  • The solution was to warp the entire script code in single quotes instead double quotes (in myjob.jobdsl file):

    definition {
     cps {
      script('''
       def user_id = ''
       wrap([$class: 'BuildUser']) {
          addBadge text: env.BUILD_USER + ', ' + params.Computer
          user_id = env.BUILD_USER_ID.toLowerCase()
       }
      ''')
     }
    }