2

I have the following DSL code and I´m getting error on line 13, $class. I guess than everything inside script("""...""") is parsed as plain text to the pipeline definition but I don´t know what´s wrong or how to escape the $ character.

My code:

pipelineJob('DSL-Test') {

parameters {
    choiceParam ('version', ['1.2.1', '1.2.0'], 'Docker Version')
}

definition {
    cps {
        sandbox(boolean sandbox = true)
        script("""
            node ('master'){
                stage('Git Checkout'){
                    checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'mycrednetial', url: 'myurl']]])
                }
            }
        """.stripIndent()) 
         }
    }
}

This is the error I get:

Processing provided DSL script ERROR: startup failed: script: 13: unexpected token: class @ line 13, column 24. checkout([$class: 'GitSCM']) ^

1 error

Started calculate disk usage of build Finished Calculation of disk usage of build in 0 seconds Started calculate disk usage of workspace Finished Calculation of disk usage of workspace in 0 seconds Finished: FAILURE

Does anyone know how to make that character not display error?

0

1 Answer 1

0

I have just managed how to escape characters.

The solution is to add: "\" before the character.

checkout([\$class:....
2
  • Could you mark this answer as resolved if this solved the issue?
    – 030
    Commented Sep 7, 2017 at 12:39
  • I tried you suggestion for the following case: wrap([$class: 'BuildUser']) but got nexpected char : '\'
    – arielma
    Commented Nov 2, 2021 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.